Download the PHP package nagyatka/pandabase without Composer
On this page you can find all versions of the php package nagyatka/pandabase. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pandabase
PandaBase
Installation
We recommend that use version above v0.20.0, because of significant API and performance changes.
How to use ConnectionManager
Get ConnectionManager instance
You can reach the ConnectionManager singleton instance globally via getInstance()
method
Add connection to manager object
You can easily set a new database connection in Pandabase.
Add more connection to manager object
ConnectionManager is able to handle more connection at time. The connections can be distinguished via the name parameter,
for example you can use "test_connection1"
and "test_connection2"
in the following example:
Get connection
The getConnection
method returns with the default connection if you leave the name parameter empty. The default connection
will be the firstly set connections.
Get connection by name
Set the default connection by name
Execute queries using ConnectionManager
How to use Connection
Connection is a PDO wrapper (all PDO function is callable) and provides a modified fetchAssoc and fetchAll methods for better usability. Although the ConnectionManager instance provides wrapper function for Connection instance's function so we recommend to use these wrapper function instead of calling them directly.
Get connection
Fetch a result row as an associative array
Returns with an array containing all of the result set rows as an associative array
Create classes based on database scheme
You can create classes based on tables of database. To achieve this, you have to only extend your classes from SimpleRecord or HistoryableRecord and register them to the specified connection.
SimpleRecord
Implement a SimpleRecord class
Assume that we have a MySQL table named as transactions and it has a primary key.
Implement Transaction class:
In next step you have to add a Table object (this is a table descriptor class) to the specified Connection instance in the following way when you initialize the connection:
And that's all! Now you can create, update and delete records from the table:
HistoryableRecord
HistoryableRecord has the same features as SimpleRecord but it also storea the previous state of a record.
Implement a HistoryableRecord class
Assume that we have a MySQL table named as transactions and the table has the following columns (all of them required):
- sequence_id (PRIMARY KEY)
- id (record identifier, you can use it as ID in your code)
- record_status (0|1 -> inactive|active)
- history_from (datetime)
- history_to (datetime)
Implement Order class:
In next step you have to add a Table object (this is a table descriptor class) to the specified Connection instance in the following way when you initialize the connection:
Now you can use HistoryableRecord as a SimpleRecord, but you can get also historical information about the instance:
Lazy attributes
Sometimes you have to store foreign keys in your table to represent connection between different objects. Without lazy attribute load you can load the objects this way:
Or if you want to provide a class method:
Instead of this, you can use LazyAttribute to implement this kind of connection on fast and easily way.
First you have to extend your table description. In our example we'd like to store an 'order_id' for a transaction record and want to reach the appropriate Order instance via 'order' key:
(We supposed that you extended the mysql table declaration too with the new 'order_id' column.)
Now you can use a Transaction instance in the following way:
####### TODO: AccessManagement
License
PandaBase is licensed under the Apache 2.0 License