我用php写了一个类,但是总是报错,mysqli_select_db() expects parameter 1 to be mysqli,怎么回事呢?
<?phpclassConnection{protected$link;private$server,$username,$password,$db;publicfunc...
<?php
class Connection
{
protected $link;
private $server, $username, $password, $db;
public function __construct($server, $username, $password, $db)
{
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->connect();
}
private function connect()
{
$this->link = mysql_connect($this->server, $this->username, $this->password);
$ret = mysqli_select_db($this->db, $this->link);
if($ret){
echo "成功连接";
}else{
echo "连接失败";
}
}
public function __sleep()
{
return array('server', 'username', 'password', 'db');
}
public function __wakeup()
{
$this->connect();
}
}
$p = new Connection('lcoalhost','root','111','testapp');
?> 展开
class Connection
{
protected $link;
private $server, $username, $password, $db;
public function __construct($server, $username, $password, $db)
{
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->connect();
}
private function connect()
{
$this->link = mysql_connect($this->server, $this->username, $this->password);
$ret = mysqli_select_db($this->db, $this->link);
if($ret){
echo "成功连接";
}else{
echo "连接失败";
}
}
public function __sleep()
{
return array('server', 'username', 'password', 'db');
}
public function __wakeup()
{
$this->connect();
}
}
$p = new Connection('lcoalhost','root','111','testapp');
?> 展开
展开全部
如果我没记错的话,
mysqli_select_db 的参数顺序和 mysql_select_db相反吧, 先link 再 数据表
两类函数不能混着用吧?现在都推荐使用mysqli 这个扩展了
mysqli_select_db 的参数顺序和 mysql_select_db相反吧, 先link 再 数据表
两类函数不能混着用吧?现在都推荐使用mysqli 这个扩展了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mysqli_select_db 改为 mysql_select_db
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询