The new version is 2.05 added a lot of support, including Codeigniter,mssql, PDO, etc.
I've written for CodeIgniter once, but I only support MySQL.
Look at the use example
In fact, there is no difficulty, directly to see the source code can be, mainly the idea of programming is very good.
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 of the full schema, 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 Class Introduction:
Ezsql is a small, fast database operation class that allows you to easily manipulate various databases in PHP (MySQL, ORACLE8/9, InterBase, Firebird, PostgreSQL, Ms-sql, SQLite, SQLite, C + + )。
At the beginning of your script is to include a PHP file. You can then use a smaller, easier set of ezsql functions to replace the standard PHP database functions.
It automatically caches query results, provides a series of simple function operations and extensions, and does not cause additional server overhead
It has excellent debugging function, so that you can quickly judge the execution of SQL statements
The result that the Ezsql function can return is an object, an associative array, or an array of values
It can greatly shorten development time and, in most cases, will simplify your code, make it run faster, and easily debug and optimize your database query statements.
This is a small class that doesn't add a lot of overhead to your site.
The following methods are available in the class:
-$db->get_results– read a dataset from a database (or a data set cached before or)
-$db->get_row-reads a data from the database (data cached before or)
-$db->get_col– reads a column from the database a specified dataset (a dataset cached before or)
-$db->get_var-reads a value from the database dataset (data cached before or)
-Executes an SQL statement $db->query-(cached if data is available)
-$db->debug– Print the last executed SQL statement and the results returned (if any)
-$DB the structure and content of->vardump– printing variables
-$db->select-Select a new database
-$db->get_col_info– to get column information
-$db->donation– Donate money to the author
-$db->escape– Format the string to insert the database, eg:mysql_escape_string (Stripslashes ($STR))
-Clear Cache $db->flush–
-$db->get_cache– in exchange for caching
-$db->hide_errors– Hidden error
-$db->register_error– Registration error
-$db->show_errors– Display Error
-$db->store_cache– Store to cache
-$db->sysdate– to get system time
-$db = new db-to create a newer DB object.
WordPress has modified the ezsql and also made it available only for MySQL
WordPress modified some of the class operation is the function is as follows:
function query ($query)
This function is the most basic function of the wpdb, $query for the SQL statement, submitted to the database query, the result is divided into two cases:
1. If it is "Insert|delete|update|replace", return the number of affected rows, and in the case of "Insert|replace", record the newly inserted ID with $this->insert_id.
2. If it is "select", write down the result set of the query with $this->last_result, and return the number of rows in the query.
function Escape ($string)
Use a backslash to refer to a string, that is, using magic quotes.
function Insert ($table, $data)
This is the Insert record function, the first parameter is the field array of the table, and the second is the data array. Insert data to return 1, otherwise 0.
function Update ($table, $data, $where)
This is the more new record function, the first argument is the field array of the table, the second is the data array, and the third is the conditional array, which is a nane array. Updated to 1, otherwise 0.
function Get_var ($query =null, $x = 0, $y = 0)
If the $query is not empty, the query is executed first, and then the value of Y row in column X is returned.
function Get_row ($query = null, $output = OBJECT, $y = 0)
Returns a row $OUTPU specifies the type to return, either Array_a,array_n or OBJECT. $Y Specifies the first few lines.
function Get_col ($query = null, $x = 0)
Returns a column $x specifies the first column.
function get_results ($query = null, $output = OBJECT)
Returns the query result set, which can be returned in either Array_a,array_n or OBJECT three ways.
function Get_col_info ($info _type = ' name ', $col _offset =-1)
Returns the field information.
There are other functions that are not detailed here. There are also two global variables, savequeries and Wp_debug, the first is that you can get access to the page to execute the query to save to the $this->queries this array, later to debug the use of, wp_debug let you put the error output. Neither of these defaults is open, and you can open it in wp_config.php when you test it.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.