mysql_query &更新查询未执行

发布于 2024-12-05 05:44:23 字数 799 浏览 0 评论 0原文

我正在尝试对表的特定行运行更新,并在每次更新运行时将列的内容加一。但是,在某些时候查询不会运行,也不会产生异常。有谁知道为什么会发生这种情况?我已尝试以下操作:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2024-12-12 05:44:23
  1. 可能实际上是数据库连接调用失败了(由于一些与数据库相关的问题,如网络问题或太多 mysql 连接等)。你可以尝试这样做:
    • 调用 mysql_connect() 后,验证数据库连接资源是否确实已创建,如果返回值错误,则开始引发异常。
  2. mysql_error() 不产生任何结果的一个非常常见的原因是当您在同一进程中打开多个数据库连接时。为了避免这种情况:
    • 在所有 mysql_query()mysql_error() 调用中,还开始将数据库连接资源作为参数传递。
  1. It might be that it is actually the database connection call which is failing (due to some database related issue like a network problem or too many mysql connections etc.). You could try doing this:
    • After your 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.
  2. A very common reason behind mysql_error() not producing anything is when you have multiple database connections open in the same process. To avoid this:
    • In all your mysql_query() and mysql_error() calls, also start passing the db connection resource as a parameter.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文