我已经使用php.its创建了一个聊天框,顺利工作。但我不知道新消息何时插入我的mysql数据库。我怎么知道呢?我已经尝试过这个代码。但它总是给我留下新的信息。
$initialCounter = 0;
$count_query = "select * from `message` where `receiver_id` = '$sender_id' AND `sender_id` = '$rid' order by `id` desc";
$count_query_res = $conn->query($count_query);
$countMsg = $count_query_res->num_rows;
$initialCounter += $countMsg;
$msgcounter = $initialCounter + $countMsg;
if($initialCounter<$msgcounter){ echo "new message";}
答案 0 :(得分:0)
插入数据库后,mysqli应返回受影响的行数,您可以使用这些行来了解数据库中是否插入了新数据。
该号码存储在$mysqli->affected_rows
示例:强>
<?php
$c = new mysqli("server","username","password","database");
$c->query("insert into table(column1,column2,column3) values('data','data','data')");
echo $c->affected_rows; // returns the affected rows
?>