php - ajax 无法连接 mysqli?

标签 php jquery mysql ajax mysqli

我正在尝试通过 ajax 调用连接 myqli。 因为我正在测试用户的数据库输入。

脚本崩溃于: $testBase = new mysqli("sfd", "sdf", "sdg", "sdf");

控制台中显示: Uncaught SyntaxError: Unexpected token <

是的,你搜索了这个问题,但大多数人在执行查询时都会遇到该错误,而当我尝试创建 mysqli 连接时,我的已经这样做了。

Ajax 脚本:

if (error == false){
var name = $('#name').val(),
    url = $('#url').val(),
    datahost = $('#datahost').val(),
    datausername = $('#datausername').val(),
    datapassword = $('#datapassword').val(),
    dataname = $('#dataname').val(),
    license = $('#license').val(),
    data = 'name='+ name +'&url='+ url +'&datahost='+ datahost +'&datausername='+ datausername +'&datapassword='+ datapassword +'&dataname='+ dataname +'&license='+ license;

$( "#trans" ).fadeIn( 500, function() {
    $.ajax({
        type: "POST",
        url: "handlers/install.php",
        data: data,
        success: function(e){ // this happen after we get result
            react(e);
        }
    });
});

}

请帮助我

handelers/install.php 的响应是:

"<br />\n<b>Warning</b>:  mysqli::mysqli(): (HY000/1130): Host 'server2.ughost.nl' is not allowed to connect to this MySQL server in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>59</b><br />\n<br />\n<b>Warning</b>:  mysqli::close(): Couldn't fetch mysqli in <b>/home/universa/public_html/klant/handlers/install.php</b> on line <b>75</b><br />\n{\"ban\":0,\"error\":0,\"license\":0,\"url\":0,\"name\":0,\"sql\":0,\"message\":\"localhost + asd + asdas+dasf\"}"

最佳答案

好吧,问题是当登录不正确时,install.php 总是发出警告。 但我需要检查它,因为这是用户输入,所以我如何修复它?

error_reporting(0);
                        $testBase = new mysqli($datahost, $datausername, $datapassword, $dataname);
                        error_reporting(1);
                        if ($testBase->connect_errno) {
                            $response['sql'] = 1;
                            $testBase->close();
                        } else {
                            //can connect with database
                            $testBase->close();

                        }

关于php - ajax 无法连接 mysqli?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29335244/

相关文章:

javascript - 如何修复使用 100% 宽度的 javascript slider 中的疯狂间距?

php - 如何从数据库中的多个表中搜索关键字并且没有公共(public)字段来连接表

MySQL - 递归两个节点之间的树路径

php - 在 preFlush 处理程序中保留新的关联实体(无限递归)

php - 类方法和常规函数之间有什么区别吗?

php - Javascript VS PHP 舍入

asp.net - 在asp.net网站中显示图片/照片

javascript - 对话框中的长度错误

php - 检查可迭代内容 PHP

php - Doctrine 2 中可选的 ManyToOne 关系