php - query() Dosent Work Inside a Function -
this question has answer here:
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); }
Comments
Post a Comment