Edit, eliminate, search, and sort table records #mysqli
Edit
by jurgen muller - 8 years ago (2016-10-02)
Maintain tables in a MySQL database
| I need to connect to a MySQL database with MySQLi table and edit, eliminate, search, and sort table records.
|
Ask clarification
2 Recommendations
This package can manipulate database table records.
There is one class that connects to database and execute queries.
Another class performs common operations with database table records based on information of the tables and fields stored in class variables.
Currently it can perform operations like creating, updating, deleting records, load records, validate record values, get a list records, delete a list of records.
Applications may create sub-classes with predefined values for specific tables with given fields.
| by Oleg Zorin package author 75 - 8 years ago (2016-10-18) Comment
Also you can use DataBase Object (DBO) paradigm.
For example, basic user DBO class:
Class User extends OZ\DBO {
public $name;
public $login;
public static $definition = array( 'table' => 'users',
'id' => 'userID',
'fields' => array(
'name' => array('type' => 'text', 'required' => true),
'login' => array('type' => 'text', 'required' => true, 'unique' => true)
)
);
function __construct($id = 0) { parent::__construct($id);
}
}
Now you can use your user object like:
-
Update name of user with ID 35:
$user = new User(35);
$user->name = 'New name';
$user->save();
-
Delete user with ID 12:
$user = new User(12);
$user->delete();
Or simple use static deleteList method:
User::deleteList(array(12));
-
Create new user and check login:
$user = new User();
$user->name = 'Name';
$user->login = 'Login';
$validation = $user->validate();
if($validation['result']) {
$user->save();
}
else {
print_r($validation['errors']);
}
-
This page provides DB class also. Simple static wrapper for PDO class. It's visible in every context of you application.
This class is required for DBO class. |
PDO DB Connector: Connect and execute common queries using PDO
This class can connect and execute common queries using PDO.
There is a base class that establishes connections to a given database using PDO. It has functions dedicated to connect to MySQL and Microsoft SQL server databases.
A sub-classe provides functions to perform common queries. Currently it can:
- Execute arbitrary SQL queries and return the results in an array
- Query a table and return a single column of results as an array
- Query a table and return all rows as an array
- Execute INSERT or UPDATE queries without prepared values
- Delete table rows that match a condition
| by Itay Segal package author 40 - 8 years ago (2016-10-10) Comment
you can you this PDO db connector |