2011-10-06 38 views
0

在我的PHP應用程序中使用ezSQL我有一個問題。從另一個文件中使用ezSQL函數

這是我的結構

的config.php代碼:

include_once "ez_sql_core.php"; 
include_once "ez_sql_mysql.php"; 
$db = new ezSQL_mysql('myuser','mypass','mydb','localhost'); 

的index.php代碼:

include('includes/config.php'); 
include('includes/functions.php'); 

echo prueba(); 

的functions.php代碼:

function prueba() 
{ 
    $users = $db->get_results("SELECT * FROM users"); 

    foreach ($users as $user) 
    { 
     echo $user->user; 
    } 
} 

,但我得到這個錯誤:

Fatal error: Call to a member function get_results() on a non-object in /web/htdocs/mydomain/includes/functions.php on line 7

我怎樣才能解決呢?

謝謝!

回答

0

導入從全局表中$db可變進你的函數的局部變量表:

function prueba() 
{ 
    global $db; 

你得到的錯誤,因爲$db對象是不是在你的函數可用。 var_dump($db);在這種情況下是你的朋友。

+0

非常感謝! – Klian

相關問題