conn.php
<?php
class Connect {
private $username;
private $password;
private $host;
private $dbx;
private $db;
private static $conn = null;

private function __construct() {

}

public function connectDB() {
$this->dbx = @mysql_connect ( $this->host, $this->username, $this->password );
mysql_query ( "SET NAMES GBK" );
if (! ($this->dbx)) {
echo ("<p>链接数据库失败</p>");
} else {
return 1;
}
}

public  function query($sql) {
mysql_query ($sql, $this->dbx );
}

public function setConn($_username, $_password, $_host, $_db) {
$this->username = $_username;
$this->password = $_password;
$this->host = $_host;
$this->db = $_db;
}

public static function getConn() {
if (self::$conn == null) {
self::$conn = new Connect ( );
}
return self::$conn;
}

public function selectDB() {
if (! @mysql_select_db ( $this->db, $this->dbx )) {
echo ("选择数据库失败");
} else {
return 1;
}
}
}
?>
test.php
<?php
include_once 'conn.php';$conn = Connect::getConn ();
$conn->setConn ( "root", "", "localhost","bbs");
$sql="select * from test";
$conn->query($sql);
?>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\php\zend6.1\Test\conn.php on line 25