ezSQL PHPÊý¾Ý¿â²Ù×÷Àà¿â

5年以前  |  阅读数:770 次  |  编程语言:PHP 

ezSQL ÏÂÔصØÖ*£º
ÏÂÔØ : ezSQL

аae±¾ÊÇ2.05Ìi¼ÓÁ˺ܶaÖ§³Ö£¬°uÀ¨ CodeIgniter,MSSQL, PDO µÈµÈ
ÎÒ֮ǰҲΪ CodeIgniter д¹ýÒ»´Î£¬²»¹ýÖ»Ö§³Ö MySQL

¿´¿´Ê¹ÓÃʾÀý
ÆaʵҲûʲôÄѶȣ¬Ö±½Ó¿´Ô´´uÂe¼´¿É£¬Ö÷ÒªÊdzÌÐoÉe¼ÆµÄ˼ÏeºÜºÃ¡£

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Àa½eÉÜ£º

ezsqlÊÇÒ»¸oСÐ͵ĿiËÙµÄÊý¾Ý¿a²Ù×÷Àa£¬¿ÉÒÔÈÃÄaºÜÈÝÒ×µØÓÃPHP²Ù×÷¸÷ÖÖÊý¾Ý¿a£¨ MySQL¡¢oracle8/9 ¡¢interbase¡¢FireBird¡¢PostgreSQL¡¢MS-SQL¡¢sqlite¡¢sqlite C++£(C)¡£
ÔÚÄaµÄ½Å±¾¿ªÍÊÇÒª°uº¬Ò»¸oÒ»¸oPHPÎļþ¡£È»ºo£¬Äa¾Í¿ÉÒÔʹÓøuС¡¢¸uÈÝÒ×µÄÒ»Ì×ezsqlº¯ÊýÀ´´uÌae±e×¼µÄPHPÊý¾Ý¿aº¯Êý¡£
Ëu»a×Ô¶¯»º´aeµÄ²eѯ½a¹u£¬Ìa¹(C)ÁËһϵÁмoµ¥µÄº¯Êý²Ù×÷¼°À(C)Õ¹£¬²¢ÇÒûÓÐÔi³É¶iÍaµÄ
þÎñÆ÷¿ªÏu
Ëu¾ßÓÐÓÅÁ¼µÄµ÷ÊÔ¹¦ÄÜ£¬Ê¹Äa¿iËÙµÄÅжÏSQLÓi¾aµÄÖ´Ðйý³Ì
ezsqlº¯Êý¿ÉÒÔµ»ØµÄ½a¹uÊǶÔÏo£¬¹ØÁªÊý×e£¬»oÊýÖµÊý×e
Ëu¿ÉÒÔ´o´oËo¶Ì¿ª
¢Ê±¼a£¬²¢ÔÚ´o¶aÊýÇe¿oÏ£¬½«¼o»¯ÄuµÄ´uÂe£¬ÈÃÆaÅܵøu¿i£¬ÒÔ¼°ºÜÈÝÒ×µ÷ÊÔºÍÓÅ»¯ÄuµÄÊý¾Ý¿a²eѯÓi¾a¡£
ÕaÊÇÒ»¸oСÀa£¬ÔÚÄaµÄÍøÕ¾Éϲ¢²»»aÔo¼ÓºÜ´oµÄ¿ªÏu¡£

ÀaÖÐÓÐÒÔϵĽ¨£º
- $db->get_results ¨C ´ÓÊý¾Ý¿aÖжÁÈ¡Êý¾Ý¼¯ (or ֮ǰ»º´aeµÄÊý¾Ý¼¯)
- $db->get_row ¡ª ´ÓÊý¾Ý¿aÖжÁÈ¡Ò»ÌoÊý¾Ý (or ֮ǰ»º´aeµÄÊý¾Ý)
- $db->get_col ¨C ´ÓÊý¾Ý¿aÖжÁÈ¡Ò»ÁÐÖ¸¶¨Êý¾Ý¼¯ (or ֮ǰ»º´aeµÄÊý¾Ý¼¯)
- $db->get_var ¡ª ´ÓÊý¾Ý¿aÊý¾Ý¼¯ÖжÁÈ¡Ò»¸oÖµ (or ֮ǰ»º´aeµÄÊý¾Ý)
- $db->query ¡ª Ö´ÐÐÒ»ÌosqlÓi¾a(Èç¹uÓÐÊý¾Ý£¬¾Í»º´aeÆðÀ´)
- $db->debug ¨C ´oÓ¡×iºoÖ´ÐеÄsqlÓi¾aÓeµ»ØµÄ½a¹u£¨Èç¹uÓнa¹u£(C)
- $db->vardump ¨C ´oÓ¡±aÁ¿µÄ½a¹¹¼°ÄÚÈÝ
- $db->select ¡ª Ñ¡ÔñÒ»¸oÐÂÊý¾Ý¿a
- $db->get_col_info ¨C »ñÈ¡ÁеÄÐÅÏ¢
- $db->donation ¨C ¾eÇ®¸ø×÷ÕßÓõÄ
- $db->escape ¨C ¸ñʽ»¯²aÈeÊý¾Ý¿aµÄ×Ö
u´®£¬eg:mysql_escape_string(stripslashes($str))
- $db->flush ¨C Ça³ý»º´ae
- $db->get_cache ¨C »»È¡»º´ae
- $db->hide_errors ¨C Òþ²Ø´iÎo
- $db->register_error ¨C ×¢²a´iÎo
- $db->show_errors ¨C ÏÔʾ´iÎo
- $db->store_cache ¨C ´ae´¢µ½»º´ae
- $db->sysdate ¨C »ñȡϵͳʱ¼a
- $db = new db ¡ª ½¨Á¢Ò»¸oÐÂdb¶ÔÏo.

wordpress¶Ôezsql½øÐÐÁËÐ޸ģ¬Í¬Ê±Ò²Ê¹Æa½oÊÊÓÃÓÚmysql

wordpressÐ޸ĺoµÄÒ»Ð(C)Àa²Ù×÷Ò²¾ÍÊǺ¯ÊýÈçÏ£º

function query($query)
Õa¸oº¯ÊýÊÇ WPDB ×i»u±¾µÄº¯Êý£¬$query Ϊ SQL Ói¾a£¬Ìa½»¸øÊý¾Ý¿a²eѯ£¬½a¹uÖ¶þÖÖÇe¿o£º
1. Èç¹uÊÇ ¡°insert|delete|update|replace¡±£¬
µ»ØÊÜÓ°ÏiÐÐÊý£¬ÔÚ ¡°insert|replace¡±µÄÇe¿oÏ£¬Óà $this->insert_id ¼Ç¼Ð²aÈeµÄID¡£
2. Èç¹uÊÇ ¡°select¡±£¬Óà $this->last_result ¼Çϲeѯ½a¹u¼¯£¬*µ»Ø²eѯµ½µÄ¼Ç¼ÐÐÊý¡£

function escape($string)
ʹÓôбÏßÒýÓÃ×Öu´®£¬¼´Ê¹ÓÃħÊoÒýºÅ¡£

function insert($table, $data)
ÕaÊDzaÈe¼Ç¼º¯Êý£¬µÚÒ»¸o²ÎÊýÊDZiµÄ×Ö¶ÎÊý×e£¬µÚ¶þ¸oÊÇÊý¾ÝÊý×e¡£²aÈeÊý¾Ýµ»Ø1£¬ñÔoΪ0¡£

function update($table, $data, $where)
ÕaÊǸuмͼº¯Êý£¬µÚÒ»¸o²ÎÊýÊDZiµÄ×Ö¶ÎÊý×e£¬µÚ¶þ¸oÊÇÊý¾ÝÊý×e£¬µÚÈý¸oÊÇÌo¼þÊý×e£¬ËuÊÇÒ»¸o nane array¡£¸uÐÂÁËΪ1£¬*ñÔoΪ0¡£

function get_var($query=null, $x = 0, $y = 0)
Èç¹u $query ²»Îª¿Õ£¬Ê×ÏÈÖ´Ðвeѯ£¬È»ºo*µ»ØµÚ X ÁÐ Y ÐеÄÖµ¡£

function get_row($query = null, $output = OBJECT, $y = 0)
µ»ØÒ»ÐУ¬$outpu Ö¸¶¨µ»ØµÄÀaÐÍ£¬¿ÉÒÔÊÇ ARRAY_A£¬ARRAY_N »oÕß OBJECT¡£$y Ö¸¶¨µÚ¼¸ÐС£

function get_col($query = null , $x = 0)
*µ»ØÒ»ÁУ¬$x Ö¸¶¨µÚ¼¸ÁС£

function get_results($query = null, $output = OBJECT)
µ»Ø²eѯ½a¹u¼¯£¬¿ÉÒÔÒÔ ARRAY_A£¬ARRAY_N »oÕß OBJECT ÈýÖֽʽ*µ»Ø¡£

function get_col_info($info_type = ¡®name', $col_offset = -1)
*µ»Ø×Ö¶ÎÐÅÏ¢¡£

ÆaËu»¹ÓÐÒ»Ð(C)º¯Êý£¬ÕaÀi²»Ïeϸ½²ÁË¡£ÁiÍa»¹ÓÐÁ½¸oÈ«¾Ö±aÁ¿£¬SAVEQUERIES ºÍ WP_DEBUG£¬µÚÒ»¸oÊÇ£¬¿ÉÒÔÈÃÄa°Ñ*ÃÎÊÒ³ÃaeÖ´ÐеIJeѯ°Ñ±£´aeµ½ $this->queries Õa¸oÊý×eÖУ¬ÒÔºoµ÷ÊÔµÄʱºoʹÓã¬WP_DEBUG ÔoÈÃÄa°Ñ´iÎoÊa³o¡£ÕaÁ½¸oĬÈ϶¼Ã»Óдo¿ª£¬Äa²aÊÔµÄʱºo¿ÉÒÔÔÚ wp_config.php Öн«Æa¿ªÆo¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例