Im using ezSQL in my PHP application and I have a problem.
This is my structure
config.php code:
include_once "ez_sql_core.php";
include_once "ez_sql_mysql.php";
$db = new ezSQL_mysql('myuser','mypass','mydb','localhost');
index.php code:
include('includes/config.php');
include('includes/functions.php');
echo prueba();
functions.php code:
function prueba()
{
$users = $db->get_results("SELECT * FROM users");
foreach ( $users as $user )
{
echo $user->user;
}
}
But i get this error:
Fatal error: Call to a member function get_results() on a non-object in /web/htdocs/mydomain/includes/functions.php on line 7
How can I fix it ?
Thanks!
Import the $db
variable from the global table into your function's local variable table:
function prueba()
{
global $db;
You get the error because the $db
object was not available in your function. var_dump($db);
is your friend in such cases.