The best PHP database operation class is ezSQL. EzSQL is a very useful PHP database operation class. The database operations of WordPress, the famous open-source blog, use the MySQL section of ezSQL. This database operation class supports almost all mainstream ezSQL statements. it is a very useful PHP database operation class. The database operations of WordPress, the famous open-source blog, use the MySQL section of ezSQL. The database operation class supports almost all mainstream databases such as: PHP-PDO, mySQL, Oracle, InterBase/FireBird, PostgreSQL, SQLite and MS-SQL. EzSQL has a strong debugging function that allows you to quickly view SQL code execution. With ezSQL, we can save development time, simplify code, and improve running efficiency.
EzSQL has the advantages of being small, fast, simple, easy to use, and open-source. There is also security. The details you didn't expect are all taken into consideration for you. You only need to include related PHP files at the beginning of your script, and then you can use a better ezSQL function to replace the standard PHP database operation function.
Below are some major functions in ezSQL:
$ Db-> get_results -- read the dataset from the database.
$ Db-> get_row -- read a row of data from the database.
$ Db-> get_col -- read a specified column of dataset from the database.
$ Db-> get_var -- read a value from the database dataset.
$ Db-> query -- execute an SQL statement.
$ Db-> debug -- print the final executed SQL statement and the returned results.
$ Db-> vardump-prints the structure and content of a variable.
$ Db-> select -- select a new database.
$ Db-> get_col_info -- get the column information.
$ Db-> hide_errors -- hide the error.
$ Db-> show_errors -- an error is displayed.
EzSQL is easy to use. first download the ezSQL source code, and then put the ez_ SQL _core.php file and the ez_ SQL _mysql.php File (mySQL is used as an example here) in the same directory as your script file, then add the following code to the beginning of your script file, so that you can use ezSQL normally.
// Core file containing ezSQL
Include_once "ez_ SQL _core.php ";
// Contains the specific database file of ezSQL. mySQL is used as an example here.
Include_once "ez_ SQL _mysql.php ";
// Initialize the database object and establish a database connection
$ Db = new ezSQL_mysql ('Db _ user', 'DB _ password', 'DB _ name', 'DB _ host ');
?>
The following is an application example of some major functions in ezSQL. the code is from the official help document of ezSQL.
Instance 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);
Instance 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;
}
Instance 9:
// Same as above ‘but quicker’
foreach ( $db->get_col("SELECT name,email FROM users",0) as $name ) {
echo $name;
}
Instance 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();
Bytes. The database operations of WordPress, the famous open-source blog, use the MySQL section of ezSQL. This database operation class supports almost all mainstream...