class mysql {
private $linkid; // PostgreSQL link identifier
private $host; // PostgreSQL server host
private $user; // PostgreSQL user
private $passwd; // PostgreSQL password
private $db; // PostgreSQL database
private $result; // Query result
private $querycount; // Total queries executed
/* Class constructor. Initializes the $host, $user, $passwd
and $db fields. */
function __construct($host, $db, $user, $passwd) {
$this->host = $host;
$this->user = $user;
$this->passwd = $passwd;
$this->db = $db;
}
/* Connects to the PostgreSQL Database */
function connect(){
try{
$this->linkid = @pg_connect("host=$this->host dbname=$this->dbuser=$this->user password=$this->passwd");
if (! $this->linkid)
throw new Exception("Could not connect to PostgreSQL server.");
}catch (Exception $e) {
die($e->getMessage());
}
}
}
private $linkid; // PostgreSQL link identifier
private $host; // PostgreSQL server host
private $user; // PostgreSQL user
private $passwd; // PostgreSQL password
private $db; // PostgreSQL database
private $result; // Query result
private $querycount; // Total queries executed
/* Class constructor. Initializes the $host, $user, $passwd
and $db fields. */
function __construct($host, $db, $user, $passwd) {
$this->host = $host;
$this->user = $user;
$this->passwd = $passwd;
$this->db = $db;
}
/* Connects to the PostgreSQL Database */
function connect(){
try{
$this->linkid = @pg_connect("host=$this->host dbname=$this->dbuser=$this->user password=$this->passwd");
if (! $this->linkid)
throw new Exception("Could not connect to PostgreSQL server.");
}catch (Exception $e) {
die($e->getMessage());
}
}
}
private $linkid; // PostgreSQL link identifier
private $host; // PostgreSQL server host
private $user; // PostgreSQL user
private $passwd; // PostgreSQL password
private $db; // PostgreSQL database
private $result; // Query result
private $querycount; // Total queries executed
/* Class constructor. Initializes the $host, $user, $passwd
and $db fields. */
function __construct($host, $db, $user, $passwd) {
$this->host = $host;
$this->user = $user;
$this->passwd = $passwd;
$this->db = $db;
}
/* Connects to the PostgreSQL Database */
function connect(){
try{
$this->linkid = @mysql_connect("host=$this->host dbname=$this->dbuser=$this->user password=$this->passwd");
if (! $this->linkid)
throw new Exception("Could not connect to PostgreSQL server.");
}catch (Exception $e) {
die($e->getMessage());
}
}
}
{
$conn = mysql_connect($dbhost, $dbuser, $dbpsw) ;
mysql_select_db($dbname, $conn) ;
return $conn;
}..................
$db = db_connect();
mysql_query('select *****', $db);
...............
function db_connect()
{
$conn = new mysqli('localhost', 'username', 'password', 'database');
return $conn;
}.....
$conn = db_connect();
$result = $conn->query('select */*******');
,,,....
function db_connect()
{
$conn = mysql_connect($dbhost, $dbuser, $dbpswd);
mysql_select_db($dbname, $conn);
return $conn;
}然后在2.php页面require db.php这个文件。2.php中的连接部分如下:
$db = db_connect();
$result = mysql_query("select ***** ,$db");
while($row = @mysql_fetch_array ($result)) {
........
}为什么什么都不输出呢?不用这个方法,直接写的话,是没问题的。
require_once('db.php');
.....
自己不会写不就用PHPLIB的 db_mysql.inc 文件里头的类!