Re: [請益] 關於php同時連接多個db
※ 引述《marcoyan (回到正軌。)》之銘言:
: 我自己回答一下好了,不過我不知這方法是不是會有問題,如果寫的不好請多指教
class Db {
private $conn;
private $res = array();
private $db_user = '';
private $db_pw = '';
private $db_host = '';
private $db_name = '';
function __construct($user, $pw, $host, $name, $conn_now = false){
$this->db_user = $user;
$this->db_pw = $pw;
$this->db_host = $host;
$this->db_name =$name;
if($conn_now) $this->connect();
}
function connect(){
$this->conn = @mysql_connect($this->db_host, $this->db_user, $this->db_pw);
if(!is_resource($this->conn)) die();
return true;
}
function duery($sql, $resname = ''){
$this->res[$resname] = mysql_query($sql, $this->conn);
return is_resource($this->res[$resname])? true : false;
}
function fetchArray($resname=''){
return mysql_fetch_array($this->res[$resname]);
}
}
$db1 = new db('u1', 'pw1', 'host1', 'dbname1');
$db2 = new db('u2', 'pw2', 'host2', 'dbname2');
這樣可能比較好用
--
Live Long and Prosper
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.217.35.191
推
09/04 14:49, , 1F
09/04 14:49, 1F
→
09/04 14:51, , 2F
09/04 14:51, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章