PHP的MySQL服务器不见了

编程入门 行业动态 更新时间:2024-10-26 14:33:11
本文介绍了PHP的MySQL服务器不见了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发的脚本有问题.我正在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服务器不见了

本文发布于:2023-11-16 18:53:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不见了   服务器   PHP   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!