面对对象案例连接数据库实例
<?php class mysql{ private $host; private $name; private $pass; function __construct($host,$name,$pass){ $this->host = $host; $this->name = $name; $this->pass = $pass; $this->connect();//这个也是必不可少的! } function connect(){ if(mysql_connect($this->host,$this->name,$this->pass)){ echo "连接成功!"; }else{ echo "连接失败!"; } } } $con = new mysql("127.0.0.1","root",""); ?>
By:珍惜少年时博客:http://www.cnblogs.com/xishaonian/
*-------------------------------------------*