在PHP PDO中使用MySQL函数准备语句 [英] Using MySQL functions in PHP PDO prepared statements
本文介绍了在PHP PDO中使用MySQL函数准备语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用PHP PDO时使用MySQL函数的正确方法是什么?函数NOW()被保存为字符串,而不是显示时间.
What's the right way of using a MySQL function while using PHP PDO? The function NOW() gets saved as a string instead of showing the time.
$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
推荐答案
我不会通过函数作为绑定参数:
I would not pass functions as the bound params:
$sth = $dbh->prepare("INSERT INTO pdo (namespace, count, teststring) VALUES (?, ?, NOW())");
$_a = 'Wishy-washy';
$_b = 123;
$sth->execute(array($_a, $_b));
这篇关于在PHP PDO中使用MySQL函数准备语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文