Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多个PDO查询并在一个函数中执行_Php_Mysql_Pdo - Fatal编程技术网

Php 多个PDO查询并在一个函数中执行

Php 多个PDO查询并在一个函数中执行,php,mysql,pdo,Php,Mysql,Pdo,是否可以使用PDO在一个PHP函数中创建2个查询并执行 我的代码看起来像这样,但我认为变量混淆了 $query = $this->db->prepare("REPLACE INTO `content` SET `id` = ?, `user_id` = ?, `date` = ?, `type` = ?, `starttime` = ?, `endtime` = ?, `breaktime` = ?, `worktime` = ?, `za` = ?"); $quer

是否可以使用PDO在一个PHP函数中创建2个查询并执行

我的代码看起来像这样,但我认为变量混淆了

$query = $this->db->prepare("REPLACE INTO `content` SET `id` = ?, `user_id` = ?, `date` = ?, `type` = ?, `starttime` = ?, `endtime` = ?, `breaktime` = ?, `worktime` = ?, `za` = ?");
        $query->bindValue(1, $setcontentid);
        $query->bindValue(2, $user_id);
        $query->bindValue(3, $currentdate);
        $query->bindValue(4, $settypedropdown);
        $query->bindValue(5, $starttime);
        $query->bindValue(6, $endtime);
        $query->bindValue(7, $breaktime);
        $query->bindValue(8, $worktime);
        $query->bindValue(9, $za);



        $queryusr = $this->db->prepare("UPDATE `users` SET `current_time_saldo` = ?, `current_holiday_saldo` = ? WHERE `id` = ? ");
        $queryusr->bindValue(1, $currenttimesaldo);
        $queryusr->bindValue(2, $urlaub);
        $queryusr->bindValue(3, $user_id);



        try{

            $query->execute();
            $queryusr->execute();

        } catch(PDOException $e){

            die($e->getMessage());
        }

PDO一次只允许执行一个查询。但是,如果您使用的是mysql,那么您可以始终使用mysqli_multi_查询函数

是的,这是完全有效的。您需要交易吗?