原文:
http://www.phpbuilder.com/columns/vaska20050722.php3Tip 1: MySQL 連結 Class
[php]class DB {
function DB() {
$this->host = "localhost"; // your host
$this->db = "myDatabase"; // your database
$this->user = "root"; // your username
$this->pass = "mysql"; // your password
$this->link = mysql_connect($this->host, $this->user,
$this->pass);
mysql_select_db($this->db);
}
}
// 在你需要開始使用資料庫的地方(記得先include起來)
$db = new $DB;[/php]
只要更改變數就可以馬上套用,讓你的程式碼更乾淨。
Tip 2: 安全性 (Dealing with Magic Quotes)