我有以下功能:
function get_config($name = '')
{
$config = array();
$row = array();
$sql = "SELECT * FROM ".$GLOBALS['prefix']."config ";
if ('' != $name) {$sql .= " WHERE name = '". $name ."'";}
$result = $GLOBALS['conn']->query($sql);
while ($row = $result->fetch()) {$config[$row['name']] = $row['value'];}
if ('' != $name){return $config[$name];}
}
我用它来调用我所有的站点设置。我想为此使用准备好的语句。
这是我添加准备语句时所做的:
function get_config($name = '')
{
$config = array();
$row = array();
$sql = "SELECT * FROM config";
if ('' != $name) {
$sql .= " WHERE name = 'home'";
}
$result = $GLOBALS['conn']->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$result->execute(array(':name' => $name));
while ($row = $result->fetch()) {
$config[$row['name']] = $row['value'];
}
if ('' != $name) {
return $config[$name];
}
}
但现在该功能不起作用。为什么不工作?