mysql_query &更新查询未执行
我正在尝试对表的特定行运行更新,并在每次更新运行时将列的内容加一。但是,在某些时候查询不会运行,也不会产生异常。有谁知道为什么会发生这种情况?我已尝试以下操作:
$intVersion = $this->intVersion + 1;
$strSql=<<<EOT
UPDATE $this->strQueryTable SET version = '$intVersion' WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
$intVersion = $this->intVersion + 1;
$strSql =<<<EOT
UPDATE $this->strQueryTable SET version = $intVersion WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
$strSql =<<<EOT
UPDATE $this->strQueryTable SET version = version + 1 WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
并且在所有情况下:
if (!$blnQueryOk) {
throw new Exception(mysql_error ());
return false;
}
所有这些都无法更新,但不会产生异常。
I am trying to run an update for a specific row of a table and increase by one the content of a column each time the update runs. However at certain times the query doesn't run and it does not produce an exception either. Does anyone know why this might be happening? I have tried the following:
$intVersion = $this->intVersion + 1;
$strSql=<<<EOT
UPDATE $this->strQueryTable SET version = '$intVersion' WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
$intVersion = $this->intVersion + 1;
$strSql =<<<EOT
UPDATE $this->strQueryTable SET version = $intVersion WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
$strSql =<<<EOT
UPDATE $this->strQueryTable SET version = version + 1 WHERE id = $this->id;
EOT;
$blnQueryOk = mysql_query ( $strSql );
and under all cases:
if (!$blnQueryOk) {
throw new Exception(mysql_error ());
return false;
}
All of them fail to update some times without producing an exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mysql_connect()
后,验证数据库连接资源是否确实已创建,如果返回值错误,则开始引发异常。mysql_error()
不产生任何结果的一个非常常见的原因是当您在同一进程中打开多个数据库连接时。为了避免这种情况:mysql_query()
和mysql_error()
调用中,还开始将数据库连接资源作为参数传递。mysql_connect()
call, verify that the db connection resource has really been created, and in case of a false return value, start throwing an exception.mysql_error()
not producing anything is when you have multiple database connections open in the same process. To avoid this:mysql_query()
andmysql_error()
calls, also start passing the db connection resource as a parameter.