EzSQL PHP database operation class library

  • 2020-03-31 20:43:51
  • OfStack

EzSQL download address:
Download: (link: #)

The new version 2.05 adds a lot of support, including CodeIgniter,MSSQL, PDO, and more
I wrote it for CodeIgniter once before, but only for MySQL

Look at an example of using
In fact, it is not difficult to see the source code directly, mainly the idea of programming is very good.

Example 1
----------------------------------------------------

// Select multiple records from the database and print them out..
The $users = $db - > Get_results ("SELECT name, email FROM users");
Foreach ($users as $user) {
// Access data using object syntax
Echo $user - > The 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 - > The name;
Echo $user - > Email;
Example 3
----------------------------------------------------

// Get one variable from the database and print it out..
$var = $db - > Get_var (" SELECT count (*) FROM the 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 - > The 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 the name and email FROM the 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 - > The debug ();
$db - > Get_results (" DESC $table_name ");
}
$db - > The debug ();

EZSQL class introduction:

Ezsql is a small, fast database manipulation class that allows you to easily manipulate various databases (MySQL, oracle8/9, interbase, FireBird, PostgreSQL, ms-sql, sqlite, sqlite C++) with PHP.
Include a PHP file at the beginning of your script. Then you can replace the standard PHP database functions with a smaller and easier set of ezsql functions.
It automatically caches query results, provides a series of simple functional operations and extensions, and imposes no additional server overhead
It has excellent debugging function, so that you can quickly judge the SQL statement execution process
Ezsql functions can return results as objects, associative arrays, or numeric arrays
It can significantly reduce development time and, in most cases, simplify your code, make it run faster, and make it easy to debug and optimize your database queries.
This is a small class and does not add much overhead to your site.

There are the following methods in the class:
- $db - > Get_results to read the data set from the database (or the previously cached data set)
- $db - > Get_row - read a piece of data from the database (or data previously cached)
- $db - > Get_col stream reads a column of the specified data set from the database (or the previously cached data set)
- $db - > Get_var - reads a value from the database dataset (data cached before or)
- $db - > Query - execute an SQL statement (if there is data, cache it)
- $db - > Debug print the last SQL statement executed and the result returned (if any)
- $db - > Vardump print the structure and contents of the variables
- $db - > Select - select a new database
- $db - > The get_col_info stream gets the information for the column
- $db - > I donation money to the author
- $db - > Escape format string inserted into the database, eg:mysql_escape_string(stripslashes($STR))
- $db - > Flush the cache
- $db - > Get_cache and swap the cache
- $db - > hide_errors
- $db - > Error was registered at register_error
- $db - > Errors are displayed in show_errors
- $db - > The store_cache wok is stored in the cache
- $db - > Sysdate and gets the system time
- $db = new db - creates a new db object.

Wordpress has modified ezsql to make it only applicable to mysql

Some of the modified wordpress class operations are as follows:

The function of the query ($query)
This function is the most basic function of WPDB. $query is an SQL statement, which is submitted to the database for query. The result is divided into two cases:
1. If "insert|delete|update|replace", return the number of affected rows. In the case of "insert|replace", use $this-> Insert_id records the newly inserted ID.
2. If "select", use $this-> Last_result takes down the query result set, returning the number of rows of records quested.

The function of escape ($string)
Use backslashes to refer to strings, using magic quotes.

The function insert ($table, $data)
This is the insert record function, the first argument is an array of fields of the table, the second is an array of data. Insert data returns 1, otherwise 0.

The function update ($table, $data, $where)
This is the update record function, the first argument is an array of fields of the table, the second is an array of data, and the third is a conditional array, which is a nane array. Updated to 1, otherwise 0.

Function get_var($query=null, $x = 0, $y = 0)
If $query is not null, the query is executed first and then returns the value of column X, row Y.

Function get_row($query = null, $output = OBJECT, $y = 0)
Returns a row, $outpu specifies the type to be returned, which can be ARRAY_A, ARRAY_N, or OBJECT. $y specifies the line.

Function get_col($query = null, $x = 0)
Returns a column and $x specifies which column.

Function get_results($query = null, $output = OBJECT)
Returns the query result set, which can be returned as ARRAY_A, ARRAY_N, or OBJECT.

Function get_col_info($info_type = 'name', $col_offset = -1)
Returns field information.

There are other functions that I won't go into here. There are also two other global variables, SAVEQUERIES and WP_DEBUG. WP_DEBUG asks you to output errors in the queries array. Both of these defaults are not turned on by default, so you can turn them on in wp_config.php while testing.

Related articles: