gpt4 book ai didi

php - 如何在两个不同表的两行中插入相同的UUID

转载 作者:行者123 更新时间:2023-11-29 06:04:33 26 4
gpt4 key购买 nike

我尝试下一个脚本:

// Insert data into mysql 

$qry="INSERT INTO $tbl_name1 (ID, REFERENCE, CODE, NAME) VALUES (UUID(), '$REFERENCE', '$CODE', '$NAME')";
$result=mysql_query($qry);

$qry2="INSERT INTO $tbl_name2 (PRODUCT) VALUES ('$ID')"; <--- Here is a problem
$result=mysql_query($qry2)

我不知道如何在两个表中同时插入相同的UUID。请帮我!我将非常感谢您的支持!

完成!!!工作脚本:

$q = "SELECT UUID() AS uid";
$res = mysql_query($q) or die('q error: '.mysql_error());
$row = mysql_fetch_assoc($res);

// Insert data into mysql
$qry="INSERT INTO $tbl_name1 (ID, REFERENCE, CODE, NAME) VALUES ('".$row['uid']."', '$REFERENCE', '$CODE', '$NAME')";
$result=mysql_query($qry) or die('err 034r '.mysql_error());

$qry2="INSERT INTO $tbl_name2 (PRODUCT) VALUES ('".$row['uid']."')";
$result=mysql_query($qry2) or die('gg2345 '.mysql_error());

最佳答案

只需在发送 INSERT 并将值放入 PHP 语句中之前执行 SELECT UUID() 即可。像这样的东西(未经测试):

$result = mysql_query("SELECT UUID() AS UUID") or die('SQL error: ' . mysql_error());
$row = mysql_fetch_assoc($result);
$UUID = $row["UUID"];

$qry="INSERT INTO $tbl_name1 (ID, REFERENCE, CODE, NAME) VALUES ('$UUID', '$REFERENCE', '$CODE', '$NAME')";
$result=mysql_query($qry);

$qry2="INSERT INTO $tbl_name2 (PRODUCT) VALUES ('$UUID ')"; <--- Here is a problem
$result=mysql_query($qry2)

另一种方法是使用用户定义的变量 ( see SQL Fiddle ):

SET @UUID = (SELECT UUID() AS UUID);
INSERT INTO test1 VALUES(@UUID, "foo");
INSERT INTO test1 VALUES(@UUID, "bar");

关于php - 如何在两个不同表的两行中插入相同的UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12175462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com