https://github.com/mastro-elfo/mydb
PHP class to manage mysqli DB
https://github.com/mastro-elfo/mydb
database mysqli php
Last synced: 3 months ago
JSON representation
PHP class to manage mysqli DB
- Host: GitHub
- URL: https://github.com/mastro-elfo/mydb
- Owner: mastro-elfo
- License: mit
- Created: 2017-05-29T14:29:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-04T15:00:47.000Z (almost 9 years ago)
- Last Synced: 2025-07-24T09:16:51.930Z (12 months ago)
- Topics: database, mysqli, php
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MYDB
See also comments in code.
## MYDB::last_query
The last executed query.
## MYDB::query
Sends a generic query. Also saves the query string to `$this->last_query`.
### Params
* string `$query` The query string
### Return
Returns `false` on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries will return a `mysqli_result` object. For other successful queries will return `true`. See also [http://php.net/manual/en/mysqli.query.php](http://php.net/manual/en/mysqli.query.php).
## MYDB::insert
Creates and sends an 'INSERT INTO' query.
### Params
* string `$table` The table name
* array `$data` Associative array. Keys are field names, Values are field values.
### Return
The last insert id on success, 0 on failure
### Example
```php
$db->insert('Table', [
'Field1' => 'Value1',
'Field2' => 'Value2'
]);
```
## MYDB::replace
Creates and sends a 'REPLACE INTO' query
### Params
* string `$table` Table name
* array `$data` Associative array. Keys are field names, Values are field values.
### Return
The last insert id on success, 0 on failure
## MYDB::update
Creates and sends an 'UPDATE' query.
### Params
* string `$table` The table name
* array `$data` Associative array. Keys are field names, Values are field values.
* array `$where` WHERE clause. Items are joined with AND.
### Return
`true` on success, `false` on failure
## MYDB::upsert
Create and sends an 'INSERT INTO' query. On duplicate key sends an 'UPDATE' query.
### Params
* string `$table` The table name
* array `$data` Associative array. Keys are field names, Values are field values.
* array `$where` WHERE clause. This became part of `$data` in the 'INSERT INTO' query, and a real WHERE clause in the 'UPDATE' query.
### Return
Returns `false` on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries will return a `mysqli_result` object. For other successful queries will return `true`. See also [http://php.net/manual/en/mysqli.query.php](http://php.net/manual/en/mysqli.query.php).
## MYDB::select
Create and sends a 'SELECT' query.
### Params
* string `$table` Table name
* mixed `$fields` array of fields names or `'*'` for all
* array `$where` WHERE clause. Items are joined with AND.
* array `$orderby` ORDER BY clause. `[field_name => 'ASC|DESC', ...]`
* mixed `$limit` LIMIT clause. Use one number to limit results number or two comma separated numbers for paging.
### Return
For successful queries return a `mysqli_result` object. Returns `false` on failure.
## MYDB::delete
Creates and sends a 'DELETE' query.
### Params
* string `$table` Table name
* array `$where` WHERE clause. Items are joined with AND.
### Return
`true` on success, `false` on failure