0
function db_execute($sql,$db,$array)
{
require(getcwd() . '/config/config.php');
if (empty($array))
{
$array = "";
print "Something wrong";
}
$connection = db_connect($db_host,$db_username,$db_password,$db);
$q = $connection->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$q ->execute(array($array));
if(!$q)
{
die("Error! " . $connection->errorInfo());
}
$result = $q -> fetchAll();
return $result;
}
$sql = "SELECT VALUE FROM users WHERE :id = :idnum";
$array = array(':id' => 'USER_ID', ':idnum' => '2');
printFormattedArray($array);
printFormattedArray(db_execute($sql,"user_db",$array));
由於某種原因,我無法從此函數獲得任何結果以返回任何結果。但是,當我用PDO準備好的語句不返回結果
$sql = "SELECT VALUE FROM users WHERE USER_ID = 2";
替代查詢它給了我所需的結果。我究竟做錯了什麼?
'printFormattedArray'後? – didierc 2013-02-14 05:29:52
它以可讀格式打印數組的功能 – 2013-02-14 05:41:04