您好我正在构建php pdo函数库,但我坚持要返回fetchObject
while while参数。当我试图加载页面时,它只是加载和加载,而不是打印任何结果。噢,我的代码:从函数返回pdo获取对象
的functions.php
function pdo_run($query, $autoval = null, $values = null) {
global $stmt;
global $db;
$values = preg_match_all("~'([^']+)'~", $query, $matches);
$stmt = $db->prepare("$query");
if (!$autoval) {
$stmt->execute($matches[0]);
}
else {
$stmt->execute($values);
}
}
function pdo_result() {
global $stmt;
if ($stmt) {
return '$stmt->fetchObject(PDO::FETCH_ASSOC)';
}
else {
trigger_error('generic ERROR: No pdo query found. Advanced info: global variable $stmt not found', E_USER_ERROR);
}
}
test.php的
pdo_run('SELECT * FROM settings');
while ($result = pdo_result()) {
echo $result['setting'] . "<br />";
echo $result['value'] . "<br />";
}
可能是什么问题呢?感谢您的帮助:)
这个功能使得完全没有意义的。你不应该使用它。 –
@Fred -ii-是的,我很抱歉,我修好了。 – aksu
@你的常识我的功能有什么问题? – aksu