duanan1946 2016-07-19 11:55
浏览 309
已采纳

数据库连接错误:无法通过套接字连接到本地MySQL服务器[重复]

I have realized the database on a hosting website and not on the mac using MySQL. I use the database to SignUp/Login in an IOS app. The database is using a PHP code for connecting.

This is the PHP code:

<?php

header('Content-type: application/json');
if($_POST) {
    $Nome   = $_POST['nome'];
    $Cognome   = $_POST['cognome'];
    $Email   = $_POST['email'];
    $DOB   = $_POST['dob'];
    $password   = $_POST['password'];
    $c_password = $_POST['c_password'];

    if($_POST['email']) {
        if ( $password == $c_password ) {

            $db_name     = '****************';
            $db_user     = '****************';
            $db_password = '*********************';
            $server_url  = 'localhost';

            $mysqli = new mysqli('localhost', $db_user, $db_name, $db_password);


            if (mysqli_connect_errno()) {
                error_log("Connect failed: " . mysqli_connect_error());
                echo '{"success":0,"error_message":"' . mysqli_connect_error() . '"}';
            } else {
                $stmt = $mysqli->prepare("INSERT INTO Users (nome, cognome, email, dob, password, c_password) VALUES (?, ?, ?, ?, ?, ?)");
                $password = md5($password);
                $stmt->bind_param('ssssss', $nome, $cognome, $email, $dob, $password, $c_password);


                $stmt->execute();

                if ($stmt->error) {error_log("Error: " . $stmt->error); }

                $success = $stmt->affected_rows;


                $stmt->close();


                $mysqli->close();
                error_log("Success: $success");

                if ($success > 0) {
                    error_log("User '$email' created.");
                    echo '{"success":1}';
                } else {
                    echo '{"success":0,"error_message":"Email Exist."}';
                }
            }
        } else {
            echo '{"success":0,"error_message":"Passwords does not match."}';
        }
    } else {
        echo '{"success":0,"error_message":"Invalid Email."}';
    }
}else {
    echo '{"success":0,"error_message":"Invalid Data."}';
}
?>

This is the error that I see when I try my database:

(HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk8/2129310/www/haer2jkqlgjql.co.nf/signUp.php on line 20

This error tells me that there are errors or there is an error in line 20, but I don't understand the reason.

</div>
  • 写回答

1条回答 默认 最新

  • duanbianweng5353 2016-07-19 11:58
    关注

    Its syntax mistake

    $mysqli = new mysqli('localhost', $db_user, $db_name, $db_password);
    

    Right syntax is

    $mysqli = new mysqli('localhost',$db_user,$db_password, $db_name);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料