Home Backend Development PHP Tutorial ezSQL PHP database operation class library_PHP tutorial

ezSQL PHP database operation class library_PHP tutorial

Jul 21, 2016 pm 03:37 PM
php download address operate support database new version yes Class 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 of this Website
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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

See all articles