php - query() Dosent Work Inside a Function -


i'm making script using php , pdo syntax. , before start wanted make shortcuts me. $db->query() = qr() , $string->fetch(pdo::fetch_obj) = fet($string)

but problem pops on page, query() doesn't work inside function

( fatal error: call member function query() on non-object )

here's code

// $db->query() = qr() function qr($str) {     return $db->query($str); } // $string->fetch(pdo::fetch_obj) = fet($string) function fet($dbq) {     return $dbq->fetch(pdo::fetch_obj); }  $qr = qr("select * example"); $fet = fet($qr);  echo "".$fet->example.""; 

because $db not available in function. have pass via function parameter.

function qr($db, $str) {     return $db->query($str); } 

don't use global variable


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -