Php 我试图在pdo中使用multi-query插入两个表,但它给出了一个致命错误:未捕获错误:调用未定义的方法pdo::multi_-query()
当我尝试使用multi-query插入时,它会给出错误,但是如果没有multi-query,它只插入第一个表,而第二个表不会得到任何数据Php 我试图在pdo中使用multi-query插入两个表,但它给出了一个致命错误:未捕获错误:调用未定义的方法pdo::multi_-query(),php,mysql,pdo,Php,Mysql,Pdo,当我尝试使用multi-query插入时,它会给出错误,但是如果没有multi-query,它只插入第一个表,而第二个表不会得到任何数据 <?php session_start(); $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_database = 'rambo'; $db = new PDO('mysql:host='.$db_hos
<?php
session_start();
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_database = 'rambo';
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$a = $_POST['invoice'];
$b = $_POST['id_ya_dawa'];
//$c = $_POST['idadi_zilizotoka'];
$w = $_POST['re_id'];
$x = $_POST['customer'];
$u = $_POST['CreatedBy'];
$t = $_POST['insurance'];
$s = $_POST['strengthtype'];
$n = $_POST['dosage'];
$age = $_POST['age'];
$l = $_POST['ApprovalRefNo'];
$result = $db->prepare("SELECT * FROM products WHERE id= :userid");
$result->bindParam(':userid', $b);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$asasa=$row['UnitPrice'];
$gen=$row['gen_name'];
$code=$row['ItemCode'];
$p=$row['profit'];
}
$sql = "INSERT INTO solditem (invoice,id_ya_dawa,name,package,re_id,customer,CreatedBy,insurance,strengthtype,dosage,age,ItemCode,UnitPrice,ApprovalRefNo,DateCreated) VALUES (:a,:b,:e,:i,:w,:x,:u,:t,:s,:n,:v,:p,:r,:l,NOW());";
$sql .= "INSERT INTO anotheritem (DateCreated,CreatedBy,UnitPrice,LastModified,LastModifiedBy,ItemName,ItemCode,ApprovalRefNo,re_id) VALUES (NOW(),:w,:u,:p,NOW(),:w,:e,:v,:r,:l)";
$q =$db -> multi_query($sql);
$q =$db -> next_result();
$q->execute(array(':a'=>$a,':b'=>$b,':e'=>$gen,':i'=>$code,':w'=>$w,':x'=>$x,':u'=>$u,':t'=>$t,':s'=>$s,':n'=>$n,':v'=>$age,':p'=>$asasa,':r'=>$code,':l'=>$l));
header("location: resale.php?re_id=$w&invoice=$a");
?>
multi_query
和next_result
是MySQLi中的函数,而不是PDO
改变
$sql = "INSERT INTO solditem (invoice,id_ya_dawa,name,package,re_id,customer,CreatedBy,insurance,strengthtype,dosage,age,ItemCode,UnitPrice,ApprovalRefNo,DateCreated) VALUES (:a,:b,:e,:i,:w,:x,:u,:t,:s,:n,:v,:p,:r,:l,NOW());";
$sql .= "INSERT INTO anotheritem (DateCreated,CreatedBy,UnitPrice,LastModified,LastModifiedBy,ItemName,ItemCode,ApprovalRefNo,re_id) VALUES (NOW(),:w,:u,:p,NOW(),:w,:e,:v,:r,:l)";
$q =$db -> multi_query($sql);
$q =$db -> next_result();
$q->execute (array(':a'=>$a,':b'=>$b,':e'=>$gen,':i'=>$code,':w'=>$w,':x'=>$x,':u'=>$u,':t'=>$t,':s'=>$s,':n'=>$n,':v'=>$age,':p'=>$asasa,':r'=>$code,':l'=>$l));
到
multi_query
和next_result
是MySQLi中的函数,而不是PDO
改变
$sql = "INSERT INTO solditem (invoice,id_ya_dawa,name,package,re_id,customer,CreatedBy,insurance,strengthtype,dosage,age,ItemCode,UnitPrice,ApprovalRefNo,DateCreated) VALUES (:a,:b,:e,:i,:w,:x,:u,:t,:s,:n,:v,:p,:r,:l,NOW());";
$sql .= "INSERT INTO anotheritem (DateCreated,CreatedBy,UnitPrice,LastModified,LastModifiedBy,ItemName,ItemCode,ApprovalRefNo,re_id) VALUES (NOW(),:w,:u,:p,NOW(),:w,:e,:v,:r,:l)";
$q =$db -> multi_query($sql);
$q =$db -> next_result();
$q->execute (array(':a'=>$a,':b'=>$b,':e'=>$gen,':i'=>$code,':w'=>$w,':x'=>$x,':u'=>$u,':t'=>$t,':s'=>$s,':n'=>$n,':v'=>$age,':p'=>$asasa,':r'=>$code,':l'=>$l));
到