Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Mysqldump Php | 1,149 | 144 | 64 | 3 days ago | 18 | April 03, 2020 | 28 | gpl-3.0 | PHP | |
PHP version of mysqldump cli that comes with MySQL | ||||||||||
Ycdatabase | 128 | 2 years ago | apache-2.0 | C | ||||||
The lightest php database framework written in c language, built in php extension, for mysql | ||||||||||
Monolog Mysql | 123 | 19 | 9 | 3 years ago | 6 | April 14, 2020 | 13 | mit | PHP | |
MySQL Handler for Monolog, which allows to store log messages to a MySQL Table | ||||||||||
Pdoone | 101 | 1 | 3 | 9 days ago | 139 | September 03, 2022 | mit | PHP | ||
It is a simple library for PHP that simplify the use of the PDO extension. | ||||||||||
Database | 81 | 3 | 1 | 6 years ago | 3 | June 01, 2014 | 3 | mit | PHP | |
PHP/MySQL database wrapper, extends PDO and PDOStatement | ||||||||||
Gdpr Dump | 73 | 2 months ago | 20 | July 28, 2022 | 1 | gpl-3.0 | PHP | |||
Utility that creates anonymized database dumps (MySQL only). Provides default config templates for Magento, Drupal and OroCommerce. | ||||||||||
Voodorm | 48 | 6 | 2 | 9 years ago | 9 | February 13, 2014 | 6 | PHP | ||
VoodOrm is a micro-ORM which functions as both a fluent select query API and a CRUD model class. VoodOrm is built on top of PDO and is well fit for small to mid-sized projects, where the emphasis is on simplicity and rapid development rather than infinite flexibility and features. VoodOrm works easily with table relationship. And offers api that gets SQL out of your way | ||||||||||
Personal Blog | 42 | a year ago | mit | PHP | ||||||
Dynamic blogsite using PHP, JS & mysql where user can register, log in, post blog with images, comment, edit profile, change password, etc. There is a separate admin panel also where admin can approve user & theirs posts & comments and manipulate the whole site. | ||||||||||
Aura.sqlschema | 38 | 16 | 6 | 7 years ago | 5 | April 29, 2016 | 3 | bsd-2-clause | PHP | |
Independent schema discovery tools for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server. | ||||||||||
Oauth2 Server Php Mysql | 33 | 3 years ago | apache-2.0 | TSQL | ||||||
DDL to create MySQL tables for PDO storage support of oauth2-server-php library |
PHP Model class which provides
With a mysql database as such on your localhost
CREATE DATABASE categorytest;
CREATE TABLE `categories` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(120) DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`created_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
require_once('vendor/autoload.php');
Db\Model::connectDb('mysql:dbname=categorytest;host=127.0.0.1','root',''); // db connection for all sub-classes
// minimum model definition
class Category extends db\Model {
static protected $_tableName = 'categories'; // database table name
}
$newCategory = new Category(array(
'name' => 'test'
));
$newCategory->save();
as Id is not set inserts the data as a new table row, $newCategory->id
is set that of the row inserted post insert
$newCategory->name = 'changed name';
$newCategory->save();
now updates existing record
new Category(array(
'name' => 'second test'
))->save();
explict ->insert()
and ->update()
methods are available, ->save()
is a wrapper around these
All methods call ->validate()
before carrying out their operation, to do your own validation overide this method in your class and throw an Exception on validation error.
returns an object for the matching row
$cat = Category::getById(1);
Via an instance method
$cat = Category::getById(1);
$cat->delete();
OR a Class method (primary key deletes only)
Category::deleteById(1);
OR all records matching a where clause
Category::deleteAllWhere('name = ?',array('changed name'));
OR all records matching a where clause, specifying order and limits with more regular SQL
Category::deleteAllWhere('name = ? ORDER BY name DESC LIMIT 2',array('changed name'));
Return an object for the first matching the name
Category::findOne_by_name('changed name');
Return an object for the first match from the names
Category::findOne_by_name(array('changed name','second test'));
Return an array of objects that match the name
Category::find_by_name('changed name');
Return an array of objects that match the names
Category::find_by_name(array('changed name','second test'));
Return the first record by ascending field 'name' as a Catgory object
Category::first_by_name('john'); // can also pass an array of values to match
Return the last record in the table when sorted by ascending field 'name' as a Catgory object
Category::last_by_name('john'); // can also pass an array of values to match
Return a count of records that match the name
Category::count_by_name('changed name');
Return a count of records that match a set of values
Category::count_by_name(array('changed name','second test'));
return the first record by ascending primary key as a Catgory object
Category::first();
return the last record in the table when sorted by ascending primary key as a Catgory object
Category::last();
return the number of rows in the table
Catgory::count();
run an arbitary statement returning a PDO statement handle to issue fetch etc... on
$st = db\Model::execute('SELECT * FROM categoies WHERE id = ? AND id = ? AND id > ?', array(1,2,6));
custom SQL after the WHERE keyword returning the first match or all matches as Model instances
fetch one Category object with a custom WHERE ... clause
$cat = Category::fetchOneWhere('id = ? OR name = ?',array(1,'test'));
fetch array of Category objects with a custom WHERE ... clause
$cat = Category::fetchAllWhere('id = ? OR name = ?',array(1,'second test'));
fetch array of Category objects, as above but this time getting the second one if it exists ordered by ascending name
$cat = Category::fetchAllWhere('id = ? OR name = ? ORDER BY name ASC LIMIT 1,1',array(1,'second test'));
Generate placeholders for an IN clause
$params = array(1,2,3,4);
$placeholders = db\Model::createInClausePlaceholders($params); // returns a string '?,?,?,?
Category::fetchAllWhere('id IN ('.$placeholders.')',$params); // use use in a query
Take a date string or unix datetime number and return a string that can be assigned to a TIMESTAMP or DATETIME field date strings are parsed into a unix date via PHPs incredibly flexible strtotime()
db\Model::datetimeToMysqldatetime('2012 Sept 13th 12:00'); // returns '2012-09-13 12:00:00'
db\Model::datetimeToMysqldatetime('next Monday'); // returns next monday midnight in the format 'YYYY-MM-DD HH:MM:SS'
db\Model::datetimeToMysqldatetime(gmdate()); // returns the current date time in the format 'YYYY-MM-DD HH:MM:SS'