I’m wondering why when i put an sql ADODB query in side a function it produces the following error:
Fatal error: Call to a member function Execute() on a non-object in -path to script-
My function is something like:
$dsn = 'mysql://user:pass@localhost/db';
$db = ADONewConnection($dsn);
function getem($q){
$r=$db->Execute($q);
return $r->RecordCount();
}
echo getem("select * from table");
Any ideas how to fix that?
Variable Scope Issue
You need to import
$dbinstance into your function usingglobalkeyword:That should do the trick.
More Info: