简体   繁体   中英

mysql_query & update query is not executing

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM