求解:Lost connection to MySQL server during query

StrayCSDN 2006-12-14 11:02:56
环境: window 2003 + mysql 5.0.27 + PHP 5.20

Warning: PDOStatement::execute() [function.PDOStatement-execute]: SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query in x:\xx.php on line 99


$db = new PDO(....);
$st = $db->prepare("Call sp_test(0);");
$st->execute();
$st = $db->prepare("Call sp_test(1);");
$st->execute();
...全文
617 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
StrayCSDN 2006-12-20
  • 打赏
  • 举报
回复
//PDO 方式
$dsn = "mysql:dbname={$name};host={$host};port={port}";
try
{
$db = new PDO($dsn, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
$db->query("SET NAMES '{$charset}'");
}
catch (PDOException $e) {
die('不能连接到数据库!');
}


// mysqli
$db = new mysqli(
$host,
$username,
$password,
$name);

$db->query("SET NAMES '{$charset}'");
懒得去死 2006-12-18
  • 打赏
  • 举报
回复
你是用什么连接数据库的,
连接的具体参数是什么
mysql(....)
mysqli(...)
贴出来看一下。

//PDO调用的时候必须关闭上次的连接才能进行下一次
$db = new PDO(....);
$st = $db->prepare("Call sp_test(0);");
$st->execute();
$st->close();
$db = new PDO(....);
$st = $db->prepare("Call sp_test(1);");
$st->execute();
$st->close();

当然你也可以这样调用:
$db = new PDO(....);
$st = $db->prepare("Call sp_test(0);Call sp_test(1);");
$st->execute();
$st->close();
StrayCSDN 2006-12-18
  • 打赏
  • 举报
回复
应该不是, 只是一个简单的本地测试

不设置参数, 同样问题

里面的语句只有 Select a from t
懒得去死 2006-12-15
  • 打赏
  • 举报
回复
一般来说是因为查询时间太长.或者是参数传递不正确,MYSQL不认识语句导致.
StrayCSDN 2006-12-15
  • 打赏
  • 举报
回复
参照 http://netevil.org/node.php?nid=795 同样不行;
-----------------------------------------------------------
I've recently discovered a few things about how the mysql client library does things that seem a bit silly to me, so I'm going to share them with you.


native prepared statements cannot take advantage of the query cache, resulting in lower performance.
native prepared statements cannot execute certains types of queries, like "SHOW TABLES"
native prepared statements don't correctly communicate column lengths for certain other "SHOW" queries, resulting in garbled results.
calling stored procedures multiple times using native prepared statements causes the connection to drop.
I recommend that you use the following attribute when working with PDO::MYSQL, available in the current PHP 5.1.3 release candidates and snapshots:

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

This causes the PDO native query parser to be used instead of the native prepared statements APIs in the mysql client, and effectively eliminates those problems.

I'll admit that the last point could well be a bug in my code; since I'll be at the MySQL Users Conference next week, I should be able to sit down with the right people and fix it.
----------------------------------------------------------------------
而且我使用 mysqli 也遇到同样的问题
zhys9 2006-12-14
  • 打赏
  • 举报
回复
给的这几行代码没法搞明白......
StrayCSDN 2006-12-14
  • 打赏
  • 举报
回复
在执行第一个存储过程的时候能得到期望的数据;

但在调用第二个的时候就出现给出的错误;

StrayCSDN 2006-12-14
  • 打赏
  • 举报
回复
而且我使用 mysqli 也遇到同样的问题


$sql = "call sp_category_get_1(0)";
$results = $db->query($sql);
while ($row = $results->fetch_object()) {
printf("%s\t%s\n", $row->a_id, $row->a_fullname);
}
$sql = "call sp_category_get_1(0)";
$r = $db->query($sql);
echo $db->error;
while ($row = $r->fetch_object()) {
printf("%s\t%s\n", $row->a_id, $row->a_fullname);
}



Lost connection to MySQL server during query
Fatal error: Call to a member function fetch_object()
StrayCSDN 2006-12-14
  • 打赏
  • 举报
回复
存储过程中就只是一个最基本的 Select 查询
懒得去死 2006-12-14
  • 打赏
  • 举报
回复
存储内部语法过程错误才回导致这样的结果。

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧