|
 |
|
เขียน OOP select ข้อมูลจาก database แล้ว error รบกวนช่วยหน่อยครับ |
|
 |
|
|
 |
 |
|
<?php
class Join {
private $table="";
private $field=""; // เก็บเป็น array ก็จะดีกว่า เพราะมีโอกาสที่ให้ข้อมูลมีหลากหลาย แต่ทำให้ดูตัวอย่างก่อน
private $data=""; // ถ้าให้ดี เก็บเป็น array() ดีกว่า
private $rs=null; // ใช้ query
function __construct($host,$root,$password,$db) // เพิ่ม connect data base อีกสักอัน
{
$cn=mysql_connect($host,$root,$password);
if($cn)
{
$select_database=mysql_select_db($db);
mysql_query("SET NAMES UTF8");
if(!$select_database)
{
$this->err(mysql_error());
}
}
else
{
$this->err(mysql_error());
}
}
public function from($table)
{
$this->table=$table;
}
public function filed($field)
{
$this->field=$field;
}
public function data($data)
{
$this->data=$data;
}
public function get()
{
$sql="Select * from ".$this->table." where ".$this->field." = '".$this->data."'";
$this->rs=mysql_query($sql);
}
function showNum() {
return mysql_num_rows($this->rs);
}
private function err($str="error message")
{
echo"<p style='color:red'>$str</p>";
}
}
$Obj = new Join();
$Obj->from("register");
$Obj->field("cf_email");
$Obj->data("[email protected]");
$Obj->get();
echo 'Num: '. $Obj->showNum(). '<br />';
?>
ลองดูครับ
|
 |
 |
 |
 |
Date :
2011-09-27 10:09:33 |
By :
kalamell |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|