conn.php
<?php
class Connect {
private $username;
private $password;
private $host;
public $dbx;
private $db;
public  $result;
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) {
$this->result=mysql_query ($sql, $this->dbx );
return $this->result;
}

public function getLink(){
return $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 'Conns.php';$conn = Connect::getConn ();
$conn->setConn ( "root", "", "localhost", "bbs" );
$conn->connectDB ();
$sql = "SELECT * FROM test";
$r=mysql_query ( $sql,$conn->getLink() );
while ( $row = mysql_fetch_array ($r) ) {
echo "<p>" . $row ["name"] . "</p>";
}
?>
不管是用getlink()还是conn.php里的public  function query()方法,始终在运行test.php页面时报
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\php\zend6.1\Test\test.php on line 9