欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ezSQL PHP數(shù)據(jù)庫操作類庫

 更新時間:2010年05月16日 23:05:37   作者:  
WordPress 使用的數(shù)據(jù)庫操作類就是它 -- ezSQL 我用了好多年了,我特別喜歡它的幾個類方法,可以有效提高代碼簡潔度。
ezSQL 下載地址:
下載 : ezSQL

新版本是2.05添加了很多支持,包括 CodeIgniter,MSSQL, PDO 等等
我之前也為 CodeIgniter 寫過一次,不過只支持 MySQL

看看使用示例
其實也沒什么難度,直接看源代碼即可,主要是程序設計的思想很好。

Example 1
----------------------------------------------------

// Select multiple records from the database and print them out..
$users = $db->get_results("SELECT name, email FROM users");
foreach ( $users as $user ) {
// Access data using object syntax
echo $user->name;
echo $user->email;
}
Example 2
----------------------------------------------------

// Get one row from the database and print it out..
$user = $db->get_row("SELECT name,email FROM users WHERE id = 2");
echo $user->name;
echo $user->email;
Example 3
----------------------------------------------------

// Get one variable from the database and print it out..
$var = $db->get_var("SELECT count(*) FROM users");
echo $var;
Example 4
----------------------------------------------------

// Insert into the database
$db->query("INSERT INTO users (id, name, email) VALUES (NULL,'justin','jv@foo.com')");
Example 5
----------------------------------------------------

// Update the database
$db->query("UPDATE users SET name = 'Justin' WHERE id = 2)");
Example 6
----------------------------------------------------

// Display last query and all associated results
$db->debug();
Example 7
----------------------------------------------------

// Display the structure and contents of any result(s) .. or any variable
$results = $db->get_results("SELECT name, email FROM users");
$db->vardump($results);
Example 8
----------------------------------------------------

// Get 'one column' (based on column index) and print it out..
$names = $db->get_col("SELECT name,email FROM users",0)
foreach ( $names as $name ) {
echo $name;
}
Example 9
----------------------------------------------------

// Same as above ‘but quicker'
foreach ( $db->get_col("SELECT name,email FROM users",0) as $name ) {
echo $name;
}
Example 10
----------------------------------------------------

// Map out the full schema of any given database and print it out..
$db->select("my_database");
foreach ( $db->get_col("SHOW TABLES",0) as $table_name ) {
$db->debug();
$db->get_results("DESC $table_name");
}
$db->debug();

EZSQL類介紹:

ezsql是一個小型的快速的數(shù)據(jù)庫操作類,可以讓你很容易地用PHP操作各種數(shù)據(jù)庫( MySQL、oracle8/9 、interbase、FireBird、PostgreSQL、MS-SQL、sqlite、sqlite C++)。
在你的腳本開頭是要包含一個一個PHP文件。然后,你就可以使用更小、更容易的一套ezsql函數(shù)來代替標準的PHP數(shù)據(jù)庫函數(shù)。
它會自動緩存的查詢結果,提供了一系列簡單的函數(shù)操作及擴展,并且沒有造成額外的服務器開銷
它具有優(yōu)良的調(diào)試功能,使你快速的判斷SQL語句的執(zhí)行過程
ezsql函數(shù)可以返回的結果是對象,關聯(lián)數(shù)組,或數(shù)值數(shù)組
它可以大大縮短開發(fā)時間,并在大多數(shù)情況下,將簡化您的代碼,讓其跑得更快,以及很容易調(diào)試和優(yōu)化您的數(shù)據(jù)庫查詢語句。
這是一個小類,在你的網(wǎng)站上并不會增加很大的開銷。

類中有以下的方法:
- $db->get_results – 從數(shù)據(jù)庫中讀取數(shù)據(jù)集 (or 之前緩存的數(shù)據(jù)集)
- $db->get_row — 從數(shù)據(jù)庫中讀取一條數(shù)據(jù) (or 之前緩存的數(shù)據(jù))
- $db->get_col – 從數(shù)據(jù)庫中讀取一列指定數(shù)據(jù)集 (or 之前緩存的數(shù)據(jù)集)
- $db->get_var — 從數(shù)據(jù)庫數(shù)據(jù)集中讀取一個值 (or 之前緩存的數(shù)據(jù))
- $db->query — 執(zhí)行一條sql語句(如果有數(shù)據(jù),就緩存起來)
- $db->debug – 打印最后執(zhí)行的sql語句與返回的結果(如果有結果)
- $db->vardump – 打印變量的結構及內(nèi)容
- $db->select — 選擇一個新數(shù)據(jù)庫
- $db->get_col_info – 獲取列的信息
- $db->donation – 捐錢給作者用的
- $db->escape – 格式化插入數(shù)據(jù)庫的字符串,eg:mysql_escape_string(stripslashes($str))
- $db->flush – 清除緩存
- $db->get_cache – 換取緩存
- $db->hide_errors – 隱藏錯誤
- $db->register_error – 注冊錯誤
- $db->show_errors – 顯示錯誤
- $db->store_cache – 存儲到緩存
- $db->sysdate – 獲取系統(tǒng)時間
- $db = new db — 建立一個新db對象.

wordpress對ezsql進行了修改,同時也使其僅適用于mysql

wordpress修改后的一些類操作也就是函數(shù)如下:

function query($query)
這個函數(shù)是 WPDB 最基本的函數(shù),$query 為 SQL 語句,提交給數(shù)據(jù)庫查詢,結果分二種情況:
1. 如果是 “insert|delete|update|replace”, 返回受影響行數(shù),在 “insert|replace”的情況下,用 $this->insert_id 記錄新插入的ID。
2. 如果是 “select”,用 $this->last_result 記下查詢結果集,返回查詢到的記錄行數(shù)。

function escape($string)
使用反斜線引用字符串,即使用魔術引號。

function insert($table, $data)
這是插入記錄函數(shù),第一個參數(shù)是表的字段數(shù)組,第二個是數(shù)據(jù)數(shù)組。插入數(shù)據(jù)返回1,否則為0。

function update($table, $data, $where)
這是更新紀錄函數(shù),第一個參數(shù)是表的字段數(shù)組,第二個是數(shù)據(jù)數(shù)組,第三個是條件數(shù)組,它是一個 nane array。更新了為1,否則為0。

function get_var($query=null, $x = 0, $y = 0)
如果 $query 不為空,首先執(zhí)行查詢,然后返回第 X 列 Y 行的值。

function get_row($query = null, $output = OBJECT, $y = 0)
返回一行,$outpu 指定返回的類型,可以是 ARRAY_A,ARRAY_N 或者 OBJECT。$y 指定第幾行。

function get_col($query = null , $x = 0)
返回一列,$x 指定第幾列。

function get_results($query = null, $output = OBJECT)
返回查詢結果集,可以以 ARRAY_A,ARRAY_N 或者 OBJECT 三種方式返回。

function get_col_info($info_type = ‘name', $col_offset = -1)
返回字段信息。

其他還有一些函數(shù),這里不詳細講了。另外還有兩個全局變量,SAVEQUERIES 和 WP_DEBUG,第一個是,可以讓你把訪問頁面執(zhí)行的查詢把保存到 $this->queries 這個數(shù)組中,以后調(diào)試的時候使用,WP_DEBUG 則讓你把錯誤輸出。這兩個默認都沒有打開,你測試的時候可以在 wp_config.php 中將其開啟。

相關文章

最新評論