【问题标题】:variable from php function in sqlite reference来自sqlite参考中的php函数的变量
【发布时间】:2018-10-28 20:57:28
【问题描述】:

我试图在 sqlite 的另一个引用中引用一个变量。现在我有这个,它只是错误

SQLSTATE[HY000]:一般错误:25 绑定或列索引超出范围

问题出在(filmnummer, acteurnummer) VALUES (film.?.filmnummer,?);"线上,我知道这是错误的,但我不知道用什么替换它,所以它可以工作。

public function add_film($title, $genre, $actor, $director, $agecategory, $warning){
        $query = $this->db->prepare(
            "INSERT INTO film
            (title, agecategorynumber) VALUES (?,?);
            INSERT INTO filmactor
            (filmnummer, actornumber) VALUES (film.?.filmnumber,?);"
        );

        $query->bindValue(1, $title);
        $query->bindValue(2, $agecategory);
        $query->bindValue(3, $title);
        $query->bindValue(4, $actor);

        try{
            $query->execute();
        }catch(PDOException $e){
            die($e->getMessage());
        }   
    }

【问题讨论】:

    标签: php sql database sqlite


    【解决方案1】:

    您可以在绑定中而不是在查询中连接值,例如:

    public function add_film($title, $genre, $actor, $director, $agecategory, $warning){
            $query = $this->db->prepare(
                "INSERT INTO film
                (title, agecategorynumber) VALUES (:a,:b);
                INSERT INTO filmactor
                (filmnummer, actornumber) VALUES (:c,:d);"
            );
    
            $query->bindValue(':a', $title);
            $query->bindValue(':b', $agecategory);
            $query->bindValue(':c', 'film'. $title . 'filmnumber');
            $query->bindValue(':d', $actor);
    
            try{
                $query->execute();
            }catch(PDOException $e){
                die($e->getMessage());
            }   
        }
    

    【讨论】:

    • 感谢您的快速响应,但遗憾的是它仍然给出了与以前相同的错误
    猜你喜欢
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 2011-02-09
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多