Home > Database > Mysql Tutorial > body text

php下查询MySQL出现“General error: 2050”错误解决

WBOY
Release: 2016-06-07 16:56:19
Original
1853 people have browsed it

今天在php下查询mysql,居然出现了ldquo;General error: 2050rdquo;的错误,后来ray给了链接,果然问题就解决了。文章已经说得

今天在php下查询mysql,居然出现了“General error: 2050”的错误,后来ray给了链接,果然问题就解决了。

文章已经说得很清楚了,下面直接引用过来:
------------------------------------------
我把PHP升级到了5.2.5版本以后,,以前写的PDO程序总是报错SQLSTATE[HY000]: General error: 2053 ,我查了很久才找到问题的解决办法。  这样的问题只会发生在两条SQL连续请求的时候,如下面的例子:


$s = $db->query("SELECT * FROM test ORDER BY poledrugie;"); var_dump($s->fetchAll()); $s = $db->query("SELECT * FROM test ORDER BY poletrzecie;"); var_dump($s->fetchAll());

这样就会报错的。两种修改方法:
1.将第二个SQL的句柄换成$s1.

$s = $db->query("SELECT * FROM test ORDER BY poledrugie;"); var_dump($s->fetchAll()); $s1 = $db->query("SELECT * FROM test ORDER BY poletrzecie;"); var_dump($s1->fetchAll());

2.在第二个SQK前,将$s清空。
$s = $db->query("SELECT * FROM test ORDER BY poledrugie;"); var_dump($s->fetchAll()); $s = ''; $s = $db->query("SELECT * FROM test ORDER BY poletrzecie;"); var_dump($s->fetchAll());

  其实可以得出一个结论,如果两个PDO请求赋值给同一个句柄,那么第二个句柄不会被覆盖掉。所以必须我们手动覆盖一次。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template