php - MySQLi 准备好的语句未采用调用过程的有效查询

标签 php mysql stored-procedures mysqli prepared-statement

$prepared = $db->prepare("
        SET @content = ?;

        CALL add_interest_if_not_exists( @content );

        SET @iid = (SELECT interests_id
                    FROM interests
                    WHERE content = @content);

        REPLACE INTO profile_interests (user_id, interests_id, likes)
        VALUES (
            ?,
            @iid,
            ?
        )
    ");
echo $db->error;

错误是:

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 'CALL add_interest_if_not_exists( @content ); SET @iid = (SELECT i' at line 3

该查询使用 MySQL 工作台(硬编码值)进行工作。为什么不在我准备好的声明中......

最佳答案

这不是单个查询,而是一组查询。

因此,您必须一一运行它们,每个都使用单独的 query()prepare()/execute() 调用。

关于php - MySQLi 准备好的语句未采用调用过程的有效查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36374226/

相关文章:

php - 根据里氏替换原则,子类是否允许拥有公共(public)方法?

php - 根据同一页面上的另一个表单刷新 mysql 的下拉输入字段,该表单使用 PHP 将新项目添加到 mysql

PHP preg_replace - 删除除 html 标签 IMG 之外的所有文本

Where 子句的 Mysql 日期问题

mysql - 合并来自 MySQL 存储过程的结果

sql - SQL触发器存储过程编译错误

php模拟用户

javascript - 多个动态下拉选择菜单不起作用 - PHP MySQL Jquery

mysql - SQL查询: Single row has multiple foreign keys from another table

mysql - 在MySql存储过程中应该遵循哪种方法来防止SQL注入(inject)