你可能会说这个问题已经问过很多次了! 你是对的,但那些不给我解决方案。 我试图使用insert事件插入插入数据和两个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总是插入为“ZERO” - 0。 看看网上给出的各种解决方案我试过:
(NEW.sent,'$x','$p');";
(NEW.sent,"$x","$p");";
和其他但每次为这两个值插入0。
$ x和$ p的数据类型是Integer和In表我已经为这两个参数获取了int值。有什么问题?
答案 0 :(得分:1)
我的建议是:
(NEW.sent, ".$x.", ".$p.");";