search
HomeBackend DevelopmentPHP TutorialezSQL PHP database operation class library_PHP tutorial

ezSQL PHP database operation class library_PHP tutorial

Jul 21, 2016 pm 03:37 PM
phpdownloadaddressoperatesupportdatabasenew versionyesClass library

ezSQL download address:
Download: ezSQL

The new version is 2.05, which adds a lot of support, including CodeIgniter, MSSQL, PDO, etc.
I have also written for CodeIgniter once before, but it only supports MySQL

Look at the usage examples
In fact, it is not difficult, just look at the source code. The main reason is that the programming idea 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 and fast database operation Class allows you to easily operate 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. You can then use a smaller, easier set of ezsql functions in place 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 functions, allowing you to quickly judge the execution process of SQL statements
The results returned by ezsql functions are objects, associative arrays, or numeric arrays
It can greatly shorten development time, and in most cases, will simplify your code, making it run faster, as well as easily Debug and optimize your database queries.
This is a small category that doesn’t add a lot of overhead to your website.The

class has the following methods:
- $db->get_results – Read the data set from the database (or previously cached data set)
- $db->get_row — Read a piece of data from the database (or previously cached data)
- $db->get_col – Read a column of specified data set from the database (or previously cached data set)
- $db-> ;get_var — Read a value from the database data set (or previously cached data)
- $db->query — Execute a sql statement (if there is data, cache it)
- $db-> ;debug – Print the last executed SQL statement and the returned result (if there is a result)
- $db->vardump – Print the structure and content of the variable
- $db->select — Select a new database
- $db->get_col_info – Get column information
- $db->donation – Donate money to the author
- $db->escape – Format strings inserted into the database , eg: mysql_escape_string(stripslashes($str))
- $db->flush – clear cache
- $db->get_cache – exchange for cache
- $db->hide_errors – hide errors
- $db->register_error – Register errors
- $db->show_errors – Show errors
- $db->store_cache – Store to cache
- $db->sysdate – Get system time
- $db = new db — Create a new db object.

wordpress has modified ezsql, and also made it only applicable to mysql

wordpress modified Some types of operations are functions as follows:

function 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 results are divided into two situations:
1. If it is "insert|delete|update|replace", return the number of affected rows. In the case of "insert|replace", use $this->insert_id to record the newly inserted ID.
2. If it is "select", use $this->last_result to record the query result set and return the number of rows of records found.

function escape($string)
Use backslashes to quote strings, that is, use 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. Returns 1 when inserting data, 0 otherwise.

function update($table, $data, $where)
This is the update 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. , it is a nane array. It is 1 if updated, 0 otherwise.

function get_var($query=null, $x = 0, $y = 0)
If $query is not empty, first execute the query and then return the value of column X and row Y.

function get_row($query = null, $output = OBJECT, $y = 0)
Returns a row, $outpu specifies the return type, which can be ARRAY_A, ARRAY_N or OBJECT. $y specifies the row number.

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

function get_results($query = null, $output = OBJECT)
Returns the query result set, which can be returned in three ways: ARRAY_A, ARRAY_N or OBJECT.

function get_col_info($info_type = ‘name’, $col_offset = -1)
Return field information.

There are some other functions, which I won’t go into details here. There are also two global variables, SAVEQUERIES and WP_DEBUG. The first one allows you to save the queries executed by the accessed page into the $this->queries array for later use in debugging. WP_DEBUG allows you to save the queries executed by the visited page. Error output. Both of these are not turned on by default. You can turn them on in wp_config.php when testing.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321907.htmlTechArticleezSQL Download address: Download: ezSQL The new version is 2.05, which adds a lot of support, including CodeIgniter, MSSQL, PDO, etc. I have written for CodeIgniter once before, but it only supports MySQL. Take a look...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How can you prevent session fixation attacks?How can you prevent session fixation attacks?Apr 28, 2025 am 12:25 AM

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

How do you implement sessionless authentication?How do you implement sessionless authentication?Apr 28, 2025 am 12:24 AM

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

What are some common security risks associated with PHP sessions?What are some common security risks associated with PHP sessions?Apr 28, 2025 am 12:24 AM

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

How do you destroy a PHP session?How do you destroy a PHP session?Apr 28, 2025 am 12:16 AM

To destroy a PHP session, you need to start the session first, then clear the data and destroy the session file. 1. Use session_start() to start the session. 2. Use session_unset() to clear the session data. 3. Finally, use session_destroy() to destroy the session file to ensure data security and resource release.

How can you change the default session save path in PHP?How can you change the default session save path in PHP?Apr 28, 2025 am 12:12 AM

How to change the default session saving path of PHP? It can be achieved through the following steps: use session_save_path('/var/www/sessions');session_start(); in PHP scripts to set the session saving path. Set session.save_path="/var/www/sessions" in the php.ini file to change the session saving path globally. Use Memcached or Redis to store session data, such as ini_set('session.save_handler','memcached'); ini_set(

How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version