我已经在托管网站上实现了数据库,而不是在使用MySQL的mac上。 我使用数据库在IOS应用程序中进行SignUp / Login。数据库使用PHP代码进行连接。
这是PHP代码:
<?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."}';
}
?>
这是我在尝试数据库时看到的错误:
(HY000 / 2002):无法通过socket&#39; /var/run/mysqld/mysqld.sock'连接到本地MySQL服务器; (2) /srv/disk8/2129310/www/haer2jkqlgjql.co.nf/signUp.php 20
此错误告诉我第20行有错误或有错误,但我不明白原因。
答案 0 :(得分:3)
语法错误
$mysqli = new mysqli('localhost', $db_user, $db_name, $db_password);
正确的语法是
$mysqli = new mysqli('localhost',$db_user,$db_password, $db_name);