PHP100中的一个教程,编写一个自定义的类
<?php
class mysql{
private $host;
private $name;
private $pass;
function __construct($host,$name,$pass){
$this->name=$name;
$this->pass=$pass;
$this->host=$host;
$this->connet();
}
function connet(){ if( mysql_connect($this->host,$this->name,$this->pass)){
echo "连接成功";
}
}
}$db=new mysql("localhost","root","");
?>最后我测试,更改服务器名,更改密码都显示错误,这很对,可是我更改用户名root时,确显示连接成功,没错误。
<?php
class mysql{
private $host;
private $name;
private $pass;
function __construct($host,$name,$pass){
$this->name=$name;
$this->pass=$pass;
$this->host=$host;
$this->connet();
}
function connet(){ if( mysql_connect($this->host,$this->name,$this->pass)){
echo "连接成功";
}
}
}$db=new mysql("localhost","root","");
?>最后我测试,更改服务器名,更改密码都显示错误,这很对,可是我更改用户名root时,确显示连接成功,没错误。
display_errors = On
error_reporting = E_ALL & ~E_NOTICE