php - Error to connection at the database: Can't connect to local MySQL server through socket -
this question has answer here:
i have realized database on hosting website , not on mac using mysql. use database signup/login in ios app. database using php code connecting.
this 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 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 not match."}'; } } else { echo '{"success":0,"error_message":"invalid email."}'; } }else { echo '{"success":0,"error_message":"invalid data."}'; } ?>
this error see when try database:
(hy000/2002): can't connect 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 there errors or there error in line 20, don't understand reason.
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);
Comments
Post a Comment