fetchAll helper function using PDO

Novax

New Member
Suppose I have a function \[code\]function fetchAll(){ $args = func_get_args(); $query = array_shift($args); $query = str_replace("%s","'%s'",$query); foreach ($args as $key => $val) { $args[$key] = mysql_real_escape_string($val); } $query = vsprintf($query, $args); if (!$query) return FALSE; $res = mysql_query($query); if (!$res) { trigger_error("db: ".mysql_error()." in ".$query); return FALSE; } $a = array(); while($row = mysql_fetch_assoc($res)) $a[]=$row; return $a;}\[/code\]and then use it like this\[code\]$a=$db->fetchAll("SELECT * FROM users WHERE status=%s LIMIT %d,%d",$status,$start,$num);\[/code\]How can I rewrite it using PDO?
Every example I can find shows only how to bind parameters directly. Should I pass variable type as well as it's value? Or make this call always 4 lines - 3 binds and execute?
 
Back
Top