Download the PHP package ezswoole/dbobject without Composer
On this page you can find all versions of the php package ezswoole/dbobject. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ezswoole/dbobject
More information about ezswoole/dbobject
Files in ezswoole/dbobject
Package dbobject
Short Description easyswoole mysqli dbObject
License Apache-2.0
Homepage https://www.easyswoole.com/
Informations about the package dbobject
基于EasySwoole/mysqli
https://github.com/easy-swoole/mysqli
由于开发频率较高,为了随时调试使用、composer不重名包,所以单独发布一份的供快速迭代
DataBase-Mysqli
EasySwoole has provide an coroutine-save orm which is base on https://github.com/ThingEngineer/PHP-MySQLi-Database-Class 。
EasySwoole/mysqli:https://github.com/easy-swoole/mysqli
Install
Base Usage
Mysqli Pool
declare MysqlPool
declare MysqlDbObject
pool is implement at easyswoole/component
Usage List
insert
Update Query
update() also support limit parameter:
Select Query
or select with custom columns set. Functions also could be used
or select just one row
or select one column value or function result
select one column value or function result from multiple rows:
Running raw SQL queries
Where / Having Methods
where()
, orWhere()
, having()
and orHaving()
methods allows you to specify where and having conditions of the query. All conditions supported by where() are supported by having() as well.
WARNING: In order to use column to column comparisons only raw where conditions should be used as column name or functions cant be passed as a bind variable.
Regular == operator with variables:
Regular == operator with column to column comparison:
BETWEEN / NOT BETWEEN:
IN / NOT IN:
OR CASE:
NULL comparison:
LIKE comparison:
Also you can use raw where conditions:
Or raw condition with variables:
Find the total number of rows matched. Simple pagination example:
Query Keywords
To add LOW PRIORITY | DELAYED | HIGH PRIORITY | IGNORE and the rest of the mysql keywords to INSERT (), REPLACE (), GET (), UPDATE (), DELETE() method or FOR UPDATE | LOCK IN SHARE MODE into SELECT ():
Also you can use an array of keywords:
Same way keywords could be used in SELECT queries as well:
Optionally you can use method chaining to call where multiple times without referencing your object over and over:
Delete Query
Ordering method
Order by values example:
If you are using setPrefix () functionality and need to use table names in orderBy() method make sure that table names are escaped with ``.
Grouping method
Join table products with table users with LEFT JOIN by tenantID
JOIN method
Join Conditions
Add AND condition to join statement
Add OR condition to join statement
Properties sharing
It is also possible to copy properties
Subqueries
Subquery init
Subquery init without an alias to use in inserts/updates/where Eg. (select * from users)
A subquery with an alias specified to use in JOINs . Eg. (select * from users) sq
Subquery in selects:
Subquery in inserts:
Subquery in joins:
EXISTS / NOT EXISTS condition
Has method
A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.
Helper methods
Disconnect from the database:
Reconnect in case mysql connection died:
Get last executed SQL query: Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.
Check if table exists:
mysqli_real_escape_string() wrapper:
Transaction helpers
Please keep in mind that transactions are working on innoDB tables. Rollback transaction if insert fails:
Error helpers
After you executed a query you have options to check if there was an error. You can get the MySQL error string or the error code for the last executed query.
Query execution time benchmarking
To track query execution time setTrace() function should be called.
Table Locking
To lock tables, you can use the lock method together with setLockMethod. The following example will lock the table users for write access.
Calling another ->lock() will remove the first lock. You can also use
to unlock the previous locked tables. To lock multiple tables, you can use an array. Example:
This will lock the tables users and log for READ access only. Make sure you use *unlock() afterwards or your tables will remain locked!