Ezsql PHP Database Operation class Library _php tutorial

Source: Internet
Author: User
Tags mssql php database codeigniter
Ezsql Download Address:
Download: Ezsql

The new version is 2.05 added a lot of support, including Codeigniter,mssql, PDO, etc.
I wrote it once for CodeIgniter, but I only supported MySQL.

See examples of Use
In fact, there is no difficulty, directly read the source code can be, mainly the idea of program design 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 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 Class Introduction:

Ezsql is a small, fast database operation class that makes it easy to operate various databases with 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 instead of 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 process of SQL statement
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 the dataset from the database (or previously cached datasets)
-$db->get_row-reads a single piece of data from the database (or previously cached data)
-$db->get_col– reads a column from the database specified data set (or previously cached dataset)
-$db->get_var-read a value from the database dataset (or previously cached data)
-$DB->query-executes an SQL statement (cached if there is data)
-$db->debug– Prints the last executed SQL statement with the returned result (if there is a result)
-$DB the structure and contents of->vardump– printing variables
-$db->select-Select a new database
-$DB->get_col_info– Get column information
-$db->donation– to donate money to the author
-$DB->escape– formatted string inserted into the database, eg:mysql_escape_string (Stripslashes ($STR))
-$db->flush– Clear Cache
-$db->get_cache– in exchange for cache
-$db->hide_errors– Hidden errors
-$db->register_error– Registration error
-$db->show_errors– Display Error
-$db->store_cache– Storage to cache
-$db->sysdate– Get system time
-$db = new db-to create a DB object.

WordPress has modified the ezsql and also made it available only for MySQL

Some of the class operations that WordPress modifies are the following functions:

function query ($query)
This function is the most basic function of wpdb, $query for SQL statements, submitted to the database query, the results are divided into two kinds of situations:
1. If it is "Insert|delete|update|replace", return the number of rows affected, and in the case of "insert|replace", use the $this->insert_id to record the newly inserted ID.
2. If "select", use the $this->last_result to write down the query result set and return the number of records rows to the query.

function Escape ($string)
Use a backslash to reference a string, which uses 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 returns 1, otherwise 0.

function Update ($table, $data, $where)
This is the new record function, the first parameter is the field array of the table, the second is the data array, and the third is the condition 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 the Y row of column X is returned.

function Get_row ($query = null, $output = OBJECT, $y = 0)
Returns a row, $OUTPU specifies the type returned, either Array_a,array_n or OBJECT. The $y specifies the first few lines.

function Get_col ($query = null, $x = 0)
Returns a column $x the specified column.

function get_results ($query = null, $output = OBJECT)
Returns the query result set, which can be returned in Array_a,array_n or OBJECT three.

function Get_col_info ($info _type = ' name ', $col _offset =-1)
Returns the field information.

There are some other functions, which 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 execution of the query is saved to the $this->queries this array, debugging later use, Wp_debug let you put the error output. These two defaults are not open and you can turn them on in wp_config.php when you test.

http://www.bkjia.com/PHPjc/321907.html www.bkjia.com true http://www.bkjia.com/PHPjc/321907.html techarticle ezsql Download Address: Download: Ezsql new version is 2.05 added a lot of support, including Codeigniter,mssql, PDO and so on I have written for CodeIgniter once, but only support MySQL to see ...

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.