我正在开发的脚本有问题.我正在Windows XAMPP上对其进行测试,并且我有一个数据库和一个表试图插入一行.我正在使用mysqli扩展名并使用准备了防止SQL注入的语句.但是,当我执行查询时,出现错误2006:MySQL服务器消失了,但是服务器运行良好.该服务器是我自己的计算机.所以我不知道会发生什么.
I have got a problem with a script that I am developing.I'm testing it on windows XAMPP and I have got a database and a table which I am trying to insert a row.I am using the mysqli extension and using prepared statements to prevent sql injection.But when I execute the query I gets Error 2006:MySQL server gone away,but the server is working well.The server is my own computer.So I don't know what happens.
这是我正在使用的代码:
This is the code I am using:
<?php header('Content-type: text/html; charset=utf-8'); if(isset($_GET['user']) && isset($_GET['pass'])){ $db = new mysqli("localhost", "root", "", "admin"); if ($db->connect_errno) { echo "Falló la conexión a MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } if (!($db = $db->prepare("INSERT INTO logins(user,pass,ip,url) VALUES (?,?,?,?)"))) { echo "Falló la preparación: (" . $mysqli->errno . ") " . $mysqli->error; } if (!$db->bind_param('ssss', $_GET['user'], $_GET['pass'],$_SERVER['REMOTE_ADDR'],$_SERVER["HTTP_REFERER"])){ echo "Falló la vinculación de parámetros: (" . $db->errno . ") " . $db->error; } if (!$db->execute()) { echo "Falló la ejecución: (" . $db->errno . ") " . $db->error; } $db->close(); } ?>谢谢
我忘了说我曾尝试使用ini_set技巧,但没有成功
I forgot to put that I have tried to use the ini_set trick,but didn't worked
推荐答案我认为问题是$db = $db->prepare,重新分配$db变量可能会导致断开连接.尝试这样写:
I think the problem is $db = $db->prepare, reassigning $db variable probably causes disconnect. Try to write it this way:
$db = new mysqli("localhost", "root", "", "admin"); $stmt = $db->prepare("INSERT INTO logins(user,pass,ip,url) VALUES (?,?,?,?)"); $stmt->bind_param('ssss', $_GET['user'], $_GET['pass'],$_SERVER['REMOTE_ADDR'],$_SERVER["HTTP_REFERER"]); $stmt->execute(); $db->close();更多推荐
PHP的MySQL服务器不见了
发布评论