Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vinceg/php-db-migration-class
PHP DB Migration Class to create and update db using migrations across environments
https://github.com/vinceg/php-db-migration-class
Last synced: about 1 month ago
JSON representation
PHP DB Migration Class to create and update db using migrations across environments
- Host: GitHub
- URL: https://github.com/vinceg/php-db-migration-class
- Owner: VinceG
- Created: 2012-06-09T19:44:45.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-06-10T00:14:45.000Z (over 12 years ago)
- Last Synced: 2024-04-15T00:06:21.995Z (8 months ago)
- Language: PHP
- Size: 103 KB
- Stars: 16
- Watchers: 5
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP-DB-Migration-Class
======================PHP DB Migration Class to create and update db using migrations across environments
Migration code based off Yii Framework
Description
----------------
Allows one to use migrations within any project without requiring to use a full blown framework
Currently supports MYSQL but class uses PDO so can support all PDO supported driversReason why this class was created is to give the option to use the great migration feature Yii Framework provides without the need to use the entire framework.
This is a standalone lightweight package that can be incorporated into any project easily.Requirements
=======================
- PHP > 5
- PHP PDOInstallation
=======================
- Extract folder into your document root where you can access that migrate.php file.
- Open config.php and update the db settings
- Test to make sure everything works by running php migrate.php through the command line.You should see something like this:
PHP DB Migration v1.0
Creating migration history table "migrations"...done.
No new migration found. Your system is up-to-date.Usage
=======================The easiest thing to do is to run:
`php migrate.php help`
It will display help and usage examples.
To Create a migration you'll do:
`php migrate.php create some_migration_name`
To run all migrations:
`php migrate.php`
Once a migration is created you can use certain methods to make the migration process easier for example:
*Code will be placed within the up() or down() methods*
`$this->createTable('tbl_name', array('id' => 'int(10) NOT NULL default "0"', 'name' => 'TEXT NULL'), 'ENGINE=InnoDB');`
`$this->insert('tbl_name', array('id' => 1, 'name' => 'test'));`
`$this->update('tbl_name', array('name' => 'new'), 'name=:name, array(':name' => 'test'));`
`$this->delete('tbl_name', 'id=:id', array(':id' => 1));`
`$this->dropTable('tbl_name');`
`$this->emptyTable('tbl_name');`
`$this->addColumn('tbl_name', 'id', 'int(10) NOT NULL default "0"');`
`$this->dropColumn('tbl_name', 'id');`
`$this->getTables();`
`$this->getTable('tbl_name');`
At any time once can just use the pdo handler directly by accessing
`$this->getDb() // Will return pdo handler`
// Also available
$this->query('SQL QUERY')->fetchAll();
$this->query('SQL QUERY')->fetch();// Change fetch mode
$this->setFetchMode(PDO::FETCH_OBJ); // the default fetch mode is PDO::FETCH_ASSOC
// Execute
$this->exec($sql);
$this->exec($sql, $params);
// Transactions
$this->transaction();
$this->commit();
$this->rollback();
// Other
$this->lastInsertId();
// Some pdo function
$this->getDb()->query();Contributors & Resources
=======================
- The Migration process code was taken from Yii Framework v1.1.10