MySQL语法错误,但仅限于通过PHP使用时

前端之家收集整理的这篇文章主要介绍了MySQL语法错误,但仅限于通过PHP使用时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试在我的数据库中重新哈希用户ID,但我遇到了困难.

PHP
include("session.PHP");
include("functions.PHP");
$conn = ConnectMysqL();
setTimezone($session->username);

$sql = "SELECT username,userid FROM users";
$result = MysqL_query($sql) or die(MysqL_error());
while($rows = MysqL_fetch_array($result)){
    $username = $rows['username'];
    $old = MysqL_real_escape_string($rows['userid']);
    $new = MysqL_real_escape_string($session->generateRandID());

    $moresql = "START TRANSACTION;
                UPDATE users SET userid='$new' WHERE userid='$old';
                UPDATE comments SET user='$new' WHERE user='$old';
                UPDATE forum_posts SET poster_name='$new' WHERE poster_name='$old';
                UPDATE forum_topics SET topic_poster_name='$new' WHERE topic_poster_name='$old';
                UPDATE images SET author='$new' WHERE author='$old';
                UPDATE likes SET user='$new' WHERE user='$old';
                UPDATE music SET author='$new' WHERE author='$old';
                UPDATE ratings SET user='$new' WHERE user='$old';
                COMMIT;";
    $newresult = MysqL_query($moresql) or die(MysqL_error());
    if(!$newresult){echo "There was a problem with changing $username's hash. \n";}
    else{echo "Changed $username's hashMysqL_close($conn);
?>

整个查询通过PHPMyAdmin完全正常工作,显然只返回零行.
但是当我尝试将实际值通过它与PHP一起使用时,它会变得很糟糕:

You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'UPDATE users SET userid='b8aca4b680707453fa4dfe1bf1d0fddb' WHERE userid='8' at line 2

没有其他错误 – 我不知道它是什么.
提前致谢,

山姆

最佳答案
原文链接:https://www.f2er.com/mysql/433429.html

猜你在找的MySQL相关文章