Php 类mysqli_stmt的对象无法转换为字符串
.我在向数据库中插入时间时遇到问题,出现错误Php 类mysqli_stmt的对象无法转换为字符串,php,mysqli,Php,Mysqli,.我在向数据库中插入时间时遇到问题,出现错误 <?php include ('includes/config.php'); $mysqli = new mysqli(DB_SERVER, DB_UNAME, DB_PASSWD, DB_NAME); if (!$mysqli) { throw new Exception($mysqli->connect_error, $mysqli->connect_errno); } $tqry = time(); $tqr
<?php
include ('includes/config.php');
$mysqli = new mysqli(DB_SERVER, DB_UNAME, DB_PASSWD, DB_NAME);
if (!$mysqli) {
throw new Exception($mysqli->connect_error, $mysqli->connect_errno);
}
$tqry = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");
if (!$tqry) {
throw new Exception($mysqli->error);
}
$tqry->bind_param('s', $tqry);
$tqry->execute();
?>
这有什么错误
提前感谢。在这里:
$tqry->bind_param('s',$tqry);
您正在将参数s
绑定到$tqry
,这是MySQL准备的语句。必须将时间存储在不同的变量中。见:
$tqry = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");
将$tqry
设置为time,然后改为使用准备好的语句覆盖它。您应该使用不同的变量名:
$now = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");
然后做:
$tqry->bind_param('s', $now);
bind_param
的参数应该是要插入的时间,而不是$tqry
。