存储过程中就只是一个最基本的 Select 查询
解决方案 »
- 大牛们看看PHP调用外部命令win系统下删目录
- flush 与 ob_flush 有什么区别啊
- 关于zend studio的问题
- 谁能介绍一下php中action 和method的具体的作用和用法?
- Warning: session_start() [function.session-start]:
- 循环1个结果集,
- 工作没交接好,公司要报案?我不知道怎么办?
- //gois原创,介绍星期几的快速算法,只需要记住一字符串//核心代码不到10行,而且可以心算,只要你能记住那个keyStr//欢迎大家帮我测试,
- 大家帮我看一下 好吗??
- SessionID的传递问题,高手们给看看。
- 生成报表的问题
- 虚拟主机的问题,WINDOWS上的PHP+UNIX上的MYSQL,这样搭配如何?
$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);
}
[/code]
Lost connection to MySQL server during query
Fatal error: Call to a member function fetch_object()
-----------------------------------------------------------
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 也遇到同样的问题
连接的具体参数是什么
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();
$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}'");