Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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
当第二个表的id依赖于第一个表时,使用php一次插入两个表_Php_Mysql - Fatal编程技术网

当第二个表的id依赖于第一个表时,使用php一次插入两个表

当第二个表的id依赖于第一个表时,使用php一次插入两个表,php,mysql,Php,Mysql,我想一次插入两个表。我可以通过php进行更新 例如:-我将添加id为1的第一个表的行,并添加第二个表的3行。我希望所有3行的id都为1。但我不知道如何执行此操作 意味着当第一个表被更新时,最后一行id应该被更新到第二个表中的所有当时被更新的行 我的php代码是 $sql="INSERT INTO run_test2(url,gh_url,platform,machine_size,browser,image_id,security_id,instance,timer,protocol,concu

我想一次插入两个表。我可以通过php进行更新

例如:-我将添加id为1的第一个表的行,并添加第二个表的3行。我希望所有3行的id都为1。但我不知道如何执行此操作

意味着当第一个表被更新时,最后一行id应该被更新到第二个表中的所有当时被更新的行

我的php代码是

$sql="INSERT INTO run_test2(url,gh_url,platform,machine_size,browser,image_id,security_id,instance,timer,protocol,concurrency,rampup,iteration,time_out,cache) values('".$_POST["url"]."','".$_POST['gh_url']."','".$_POST['platform']."','".$_POST['inst_type']."','".$_POST['browsers']."','".$_POST['imageid']."','".$_POST['sgid']."','".$_POST['instance']."','".$_POST['timer']."','".$_POST['protocol']."','".$_POST['concurrency']."','".$_POST['rampup']."','".$_POST['iteration']."','".$_POST['time_out']."','".$_POST['radio']."');";
for($a=0;$a<3;$a++){
$sql .="INSERT INTO file_email2(filename,email) VALUES('url.jmx','vidya@gmail.com');";
}
//mysqli_query($conn,$sql);
if (mysqli_multi_query($GLOBALS['db'], $sql)) {
      include_once "header.php";
    echo "Your Test Saved ,Successfully!";
} 
else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($GLOBALS['db']);
}
它的输出如下所示:

运行试验(第一个表)

在第二个表中:

但在第二个表中,我希望输出如下:


我已经这样做了,它工作得非常好。工作很好

(1) 1.我已经取下了扳机 (从_runtest2;触发的_拖放触发器) 2()。在php中,我使用过这样的

$sql="INSERT INTO run_test2(url,gh_url,platform,machine_size,browser,image_id,security_id,instance,timer,protocol,concurrency,rampup,iteration,time_out,cache) values('".$_POST["url"]."','".$_POST['gh_url']."','".$_POST['platform']."','".$_POST['inst_type']."','".$_POST['browsers']."','".$_POST['imageid']."','".$_POST['sgid']."','".$_POST['instance']."','".$_POST['timer']."','".$_POST['protocol']."','".$_POST['concurrency']."','".$_POST['rampup']."','".$_POST['iteration']."','".$_POST['time_out']."','".$_POST['radio']."');";

$concur_sql = "SELECT  max(id) from run_test2;";
$result_concur_sql = mysqli_query($GLOBALS['db'],$concur_sql);
$row=mysqli_fetch_array($result_concur_sql);
        //maximum concurrency
$max_con=$row['max(id)'];
$max_con=$max_con+1;
for($a=0;$a<3;$a++){
$sql .="INSERT INTO file_email2(id,filename,email) VALUES('".$max_con."','url.jmx','vidya@gmail.com');";
}
//mysqli_query($conn,$sql);
if (mysqli_multi_query($GLOBALS['db'], $sql)) {
      include_once "header.php";
    echo "Your Test Saved ,Successfully!";
} 
else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($GLOBALS['db']);
}
$sql=“插入运行测试2(url、gh_url、平台、机器大小、浏览器、图像id、安全id、实例、计时器、协议、并发、爬升、迭代、超时、缓存)值(“$_POST[“url”]。”、“$_POST[“gh_url”]。”、“$_POST[“平台”]、“$_POST[“inst_type”]、“$"$"POST[“浏览器”]、“$"POST[“浏览器”、“$"图像id”、"POST["“$POST['timer']。”、“$POST['protocol']。”、“$POST['concurrency']。”、“$POST['rampup']。”、“$POST['iteration']。”、“$POST['time\u out']。”、“$POST['radio'];”;
$concur_sql=“从run_test2;中选择max(id)”;
$result\u concur\u sql=mysqli\u query($GLOBALS['db'],$concur\u sql);
$row=mysqli\u fetch\u数组($result\u concur\u sql);
//最大并发
$max_con=$row['max(id)';
$max_con=$max_con+1;

对于($a=0;$AcFER)如何获得最后插入的ID.PHPRON一个查询,获取最后插入的ID(如SUMESH的链接之上),运行第二个查询。对于此,您不能使用MulyQuy查询命令。如果需要完整性,则应该考虑在事务中包装两个查询。(即,要么两个都应插入,要么如果其中一个失败,则两个都必须失败,以免获得损坏或不完整的数据)
$sql="INSERT INTO run_test2(url,gh_url,platform,machine_size,browser,image_id,security_id,instance,timer,protocol,concurrency,rampup,iteration,time_out,cache) values('".$_POST["url"]."','".$_POST['gh_url']."','".$_POST['platform']."','".$_POST['inst_type']."','".$_POST['browsers']."','".$_POST['imageid']."','".$_POST['sgid']."','".$_POST['instance']."','".$_POST['timer']."','".$_POST['protocol']."','".$_POST['concurrency']."','".$_POST['rampup']."','".$_POST['iteration']."','".$_POST['time_out']."','".$_POST['radio']."');";

$concur_sql = "SELECT  max(id) from run_test2;";
$result_concur_sql = mysqli_query($GLOBALS['db'],$concur_sql);
$row=mysqli_fetch_array($result_concur_sql);
        //maximum concurrency
$max_con=$row['max(id)'];
$max_con=$max_con+1;
for($a=0;$a<3;$a++){
$sql .="INSERT INTO file_email2(id,filename,email) VALUES('".$max_con."','url.jmx','vidya@gmail.com');";
}
//mysqli_query($conn,$sql);
if (mysqli_multi_query($GLOBALS['db'], $sql)) {
      include_once "header.php";
    echo "Your Test Saved ,Successfully!";
} 
else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($GLOBALS['db']);
}