我一直在尝试使用 mysql 运行我的存储过程,但没有成功。每当我使用下面的代码时
$link_id = DbConnection::getInstance('mycon')->connectMysql();
$table_count = mysql_query("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'mycon' AND table_name LIKE 'table_%' ")
while($row = mysql_fetch_array($table_count)){
$table = $row["TABLE_NAME"];
$excute = mysql_query("dummy_2('$table')") or die(mysql_error());
$result = mysql_fetch_assoc($excute);
var_dump($result);
}
报错
Commands out of sync; you can't run this command now
所以当我在网上搜索时,它说我需要使用 MYSQL PDO.. 因此任何人都可以将我的上述语句转换为 mysql pdo.. 因为我对 PDO 没有任何线索
最佳答案
当您从 MySQL 数据库中查询某些内容时,结果将显示为结果集。实际上一些查询可能有多个关联的结果集。但是每个连接只能有一个事件的结果集列表。 IE。您,您的脚本必须以某种方式关闭所有当前事件的结果集,然后才能发出另一个查询。
如果例如您存储的函数使用多个 SELECTs 该函数有多个结果集,您必须迭代/关闭/删除它们。
http://dev.mysql.com/doc/refman/5.1/en/stored-routines-syntax.html :
MySQL supports a very useful extension that enables the use of regular SELECT statements (that is, without using cursors or local variables) inside a stored procedure. The result set of such a query is simply sent directly to the client. Multiple SELECT statements generate multiple result sets, so the client must use a MySQL client library that supports multiple result sets.
旧的、已弃用的 mysql_* 函数不支持多个结果集——您根本无法迭代/删除它们。
mysqli_* 扩展做:见http://docs.php.net/mysqli.next-result
PDO 也是如此:请参阅 http://docs.php.net/pdostatement.nextrowset.php
关于php - 正常的 MYSQL 不工作要求 PDO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036897/