我创建了一个具有 2 个函数的类,这些函数处理与数据库的连接并进行查询。其中一个调用另一个。这是我的代码,但它给了我错误....调用函数时肯定有问题。谁能帮我?
class DB{
public function connect(){
session_start();
include_once('libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->setTemplateDir('templates/');
$smarty->setCompileDir('templates_c/');
$smarty->setConfigDir('configs/');
$smarty->setCacheDir('cache/');
$host = "localhost";
$user = "root";
$pass = "pass";
$tablename = "table";
return $connect = mysql_connect($host, $user, $pass);
mysql_select_db($tablename, $connect) or die(mysql_error());
}
public function do_query($query){
echo DB::connect();
if(mysql_query($query,DB::connect())){
$message="Annuncio inserito correttamente!!";
echo $message;
}else{
$message="Error insert data into DB: ";
echo $message. mysql_error();
}
}
}