| new Database () | ใช้สร้าง object ของ Library Database |
|---|---|
| query() | ใช้ประมวลผลคำสั่ง sql ที่กำหนด |
| last_query() | ใช้คืนค่า คำสั่ง sql ล่าสุด ที่ได้ประมวลผลไปยังฐานข้อมูล |
| list_fields() | ใช้คืนค่า ชื่อคอลัมน์ ของ table ที่กำหนด |
| field_data() | ใช้คืนค่า รายละเอียดต่างๆ ของ table ที่กำหนด |
| table_exists() | ใช้ตรวจสอบว่ามี table ที่กำหนด อยู่ใน database จริงหรือไม่ |
| list_tables() | ใช้คืนค่า ชื่อ table ทั้งหมด ของ database ที่กำลังติดต่ออยู่ |
| insert_id() | ใช้คืนค่า ข้อมูลของ field ที่เป็นแบบ auto_increment ของ record ล่าสุดที่ถูกเพิ่มลงใน table |
| count() | ใช้คืนค่า จำนวนแถวข้อมูล ของ result |
method:new Database ( config_name );
return type:Object
content:ใช้สร้าง object ของ Library Database
example:$conn = new Database ();
comment:ตัวแปร config_name คือ key ของ config ที่ต้องการใช้ในการติดต่อกับฐานข้อมูล ที่อยู่ใน folder "system/config/database.php" โดยถ้าไม่กำหนดจะถือเป็นการใช้ค่า default ของมัน
method:query ( sql );
return type:void, result
content:ใช้ประมวลผลคำสั่ง sql ที่กำหนด ถ้าเป็นคำสั่ง select จะคืนค่า result กลับมา แต่ถ้าเป็นคำสั่งพวก insert, update, delete จะคืนค่า void กลับมา
example:$sql = "select * from bamboolabcode"; $conn = new Database (); $conn->query ( $sql );
method:last_query ();
return type:string
content:ใช้คืนค่า คำสั่ง sql ล่าสุด ที่ได้ประมวลผลไปยังฐานข้อมูล นิยมใช้ในการ debug โปรแกรมที่เขียน
example:$sql = "select * from bamboolabcode"; $conn = new Database (); $conn->query ( $sql ); echo $conn->last_query ();
method:list_fields ( table_name );
return type:array
content:ใช้คืนค่า ชื่อคอลัมน์ ของ table ที่กำหนด
example:$conn = new Database (); print_r ( $conn->list_fields ( "bamboolabcode" ) );
method:field_data ( table_name );
return type:array
content:ใช้คืนค่า รายละเอียดต่างๆ ของ table ที่กำหนด โดยจะคืนค่ามาเป็น array 2 มิติ ที่มี key ของ มิติที่ 1 ได้แก่ field, type, null, key, default, extra
example:$conn = new Database (); print_r ( $conn->field_data ( "bamboolabcode" ) );
method:table_exists ( table_name );
return type:boolean
content:ใช้ตรวจสอบว่ามี table ที่กำหนด อยู่ใน database จริงหรือไม่
example:$conn = new Database (); if ( ! $conn->table_exists ( "bamboolabcode" ) ) { echo "Not have table bamboolabcode."; }
method:list_tables ();
return type:array
content:ใช้คืนค่า ชื่อ table ทั้งหมด ของ database ที่กำลังติดต่ออยู่
example:$conn = new Database (); print_r ( $conn->list_tables () );
method:insert_id ();
return type:int
class:result
content:ใช้คืนค่า ข้อมูลของ field ที่เป็นแบบ auto_increment ของ record ล่าสุดที่ถูกเพิ่มลงใน table
example:$sql = "insert into bamboo ( id, name ) values ( 10, 'panda' ) "; $conn = new Database (); $result = $conn->query ( $sql ); echo $result->insert_id ();
method:count ();
return type:int
class:result
content:ใช้คืนค่า จำนวนแถวข้อมูล ของ result
example:$sql = "select * from bamboolabcode"; $conn = new Database (); $result = $conn->query ( $sql ); echo $result->count ();