21,886
社区成员
发帖
与我相关
我的任务
分享
mysql_connect($server, $username, $password)
mysqli_connect($server, $username, $password,$database)
public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysql_pconnect' : 'mysql_connect';
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}
if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysql_query("SET $serverset", $this->link);
}
if($this->config['database'] && !@mysql_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}
public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysql_pconnect' : 'mysqli_connect';
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], $this->config['database'])) {
$this->halt('Can not connect to MySQL server');
return false;
}
if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysql_query("SET $serverset", $this->link);
}
if($this->config['database'] && !@mysql_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
[/quote]if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], '这里改为你程序使用到的数据库名称'))
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'],$this->config['database'])) {
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
[/quote]
数据库不存在,你发上来的时候数据库名就是1,这边没有修改,可以检查一下程序配置使用的是哪一个数据库名称修改一下就行。
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], '这里改为你程序使用到的数据库名称'))
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
public function connect() {
$func = $this->config['pconnect'] == 1 ? 'mysqli_pconnect' : 'mysqli_connect';
if(!$this->link = @$func($this->config['hostname'], $this->config['username'], $this->config['password'], 1)) {
$this->halt('Can not connect to MySQL server');
return false;
}
if($this->version() > '4.1') {
$charset = isset($this->config['charset']) ? $this->config['charset'] : '';
$serverset = $charset ? "character_set_connection='$charset',character_set_results='$charset',character_set_client=binary" : '';
$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',')." sql_mode='' ") : '';
$serverset && mysqli_query("SET $serverset", $this->link);
}
if($this->config['database'] && !@mysqli_select_db($this->config['database'], $this->link)) {
$this->halt('Cannot use database '.$this->config['database']);
return false;
}
$this->database = $this->config['database'];
return $this->link;
}