你可能会说这个问题已经问了很多次了!你是对的,但那些不给我解决方案。我正在尝试使用插入事件触发器将插入的数据和两个 var 插入数据库,代码在这里:
< html > <body >
<?php
$s = $_POST['sent'];
echo "Entered sentence : $s";
$a = array();
$b = array();
if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec("/home/technoworld/Videos/LinSocket/client '$s'"), $matches))
//if (preg_match_all('/[^=]*=([^;@]*)/', shell_exec('/home/technoworld/Videos/LinSocket/client '.escapeshellarg($s)), $matches))
{
$a[] = (int) $matches[1][0]; //optionally cast to int
$b[] = (int) $matches[1][1];
}
$x = (int) $matches[1][0];
$y = (int) $matches[1][1];
$p=10;
$q=20;
echo $x;
echo "<br/>";
echo $p;
echo "<br/>";
//---------------DB stuff --------------------
$con = mysqli_connect('127.0.0.1:3306', 'root', 'root', 'test');
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
$sql2 = "CREATE TRIGGER MysqlTrigger AFTER INSERT ON table1 FOR EACH ROW BEGIN INSERT INTO temp VALUES (NEW.sent,'".$x."','".$p."');";
mysqli_query($con,$sql2);
$sql1 = "INSERT INTO table1 (sent)VALUES('$_POST[sent]')";
if (!mysqli_query($con, $sql1)) {
die('Error: '.mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</html > </body >
数据成功插入table1,触发事件也有效。但是在触发器 NEW.sent 被插入,而其余两个 var 始终插入为“零”- 0。查看网络上给出的各种解决方案,我尝试使用:
(NEW.sent,'$x','$p');";
(NEW.sent,"$x","$p");";
和其他,但每次它为这两个值插入 0。
$x 和 $p 的数据类型是整数,在表中我为这两个参数取了 int 值。问题是什么?