【问题标题】:Error when Updating Database using Stored Procedure使用存储过程更新数据库时出错
【发布时间】:2017-03-12 21:55:21
【问题描述】:

下面是我的php代码

$token = md5(uniqid(rand(), true));
        $complete = 'No';
        $update_sql = "CALL updatetoken ('$db_email','$token','$complete')";
        echo $update_sql;
        // $update_sql = "UPDATE user SET resetToken = {$token}, resetCompleted='No' WHERE email = {$_POST['email']}";
        $sqlfile = mysqli_query($connection, $update_sql);

        if ($sqlfile) {
            echo "Update successful";

        } else {
            echo "Error updating the database";
        }

然后是存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `updatetoken` (IN `usermail` VARCHAR(100), IN `token` VARCHAR(100), IN `completetask` VARCHAR(100))  UPDATE user SET resetToken = token, resetCompleted = completetask WHERE email = usermail$$

我没有更新数据库,而是不断收到错误消息“更新数据库时出错”,我尝试从我的 php 代码中使用普通的“INSERT”mysql 方法而不是 CALL,但仍然是相同的错误消息

【问题讨论】:

  • 你有确切的错误信息吗?
  • 是的,还是一样的错误

标签: php mysql database stored-procedures


【解决方案1】:

更新语句末尾缺少分号(;):

【讨论】:

  • 分号即使插入,也会被 DBMS 自动删除...我试过了,但它一直被删除
【解决方案2】:
token = md5(uniqid(rand(), true));
$complete = 'No';
$update_sql = "CALL updatetoken ('$db_email','$token','$complete')";
echo $update_sql; 

// $update_sql = "UPDATE user SET resetToken = {$token}, resetCompleted='No' WHERE email = {$_POST['email']}";
$sqlfile = mysqli_query($connection, $update_sql);
if ($sqlfile) { echo "Update successful"; } 
else { echo "Error updating the database";`

【讨论】:

  • 从上面我认为你的代码和我的代码是相似的东西,仍然无法正常工作
猜你喜欢
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多