Andy's Blog » ezsql, php db类, PHP DB, php db类库, ez_sql, php db 类, class, ezSQL文档 » 我最喜爱的 PHP DB 类库 ezSQL

我最喜爱的 PHP DB 类库 ezSQL

WordPress 使用的数据库操作类就是它 -- ezSQL
我用了好多年了,我特别喜欢它的几个类方法,可以有效提高代码简洁度。

ezSQL 下载地址:
下载 : 最好的 PHP DB 类 ezSQL 2010-04-13 (60.53 KB, 已下载 1348 次)

新版本是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','[email protected]')");

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();

Incoming search terms:

Tags: class, ezSQL, wpdb,

本文地址: http://www.21andy.com/new/20100413/1863.html

3 评论 to “PHP开源CMS之MODx”

  1. 无名 于 2011-03-18 16:44:15 发表:

    用 ezSQL 完以后不用关闭数据库连接吗?它会自己关闭吗?邮箱等解答,/哈哈谢谢了

    mohock 于 2012-05-11 17:38:29 回复:

    php机制会自动释放~

  2. wwek 于 2012-11-01 10:52:40 发表:

    我可以理解为 php sql操作的 框架么呵呵·