求php链接MySql代码
越详细越好,谢谢!
越详细越好,谢谢!
答案:class db_conn
{
private $host = 'localhost';//主机名
private $user = 'root';//用户名
private $pass = '';//密码
private $data = 'databasename';//数据库名称
private $connect;
private $result;
function __construst() //PHP5连接
{
$this->db_conn();
}
function db_conn() //PHP4连接
{
@$this->connect =mysql_connect($this->host,$this->user,$this->pass,$this->data);
if ($this->connect){
//return true;
mysql_query("setnames 'utf-8'");
}else{
die ('CONN: NOTMYSQL');
}
}
function db_query($query){
@$result =mysql_db_query($this->data,$query);
if($result){
$this->result =$result;
return$this->result;
}else{
return false;
}
}
function db_num($result){
if($result == "")
{
$result =$this->result;
}
@$number = mysql_num_rows($result);
return $number;
}
function db_close(){
@mysql_close($this->connect);
}
}
?>里面含有php 5 、php4的连接方法,和Java的思想是一样的,你可以参考参考
上一个:php网站项目如何运行
下一个:PHP中setcookie错误问题