mysqli_stmt类的对象无法转换为字符串

时间:2014-02-22 03:28:20

标签: 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();
$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();
?>

这有什么错误?

提前感谢..

1 个答案:

答案 0 :(得分:1)

就在这里:

$tqry->bind_param('s',$tqry);

您绑定参数s$tqry这是您准备好的MySQL语句。您必须将时间存储在另一个变量中。参见:

$tqry = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

您将$tqry设置为时间,然后用准备好的语句覆盖它。您应该使用不同的变量名称:

$now  = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

然后做:

$tqry->bind_param('s', $now);