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¡£
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8