【发布时间】:2011-11-29 02:55:26
【问题描述】:
在使用 PHP PDO 时使用 MySQL 函数的正确方法是什么? NOW() 函数被保存为字符串而不是显示时间。
$sth = $dbh->prepare("INSERT INTO pdo (namespace, count, teststring) VALUES (?, ?, ?)");
// these protect you from injection
$sth->bindParam(1, $_a);
$sth->bindParam(2, $_b);
$sth->bindParam(3, $_c);
$_a = 'Wishy-washy';
$_b = 123;
$_c = 'NOW()'; // Doesn't work. Comes out as the string 'NOW()' (w/o the quotes) and not as a date
【问题讨论】:
-
teststring会一直是NOW()吗?如果是这样,请直接将其放入查询中。 -
是的。但是为了争论,是否可以使用
bindParam()中的函数?