PHPSchemaManager is a library that helps you to write simple (yet powerful) code to manage MySQL databases. PHPSchemaManager tries to use a simple language to perform the desired taks and transformations in the schemas. This library is in its very beginning and will evolve to support other DBMSs too. In case you find an issue, please report it or send a Pull Request with the fix.
You will need PHP >= 5.3.0. These are the required PHP libraries:
- mbstring
- mysql
MySQL >= 5 is needed.
Include the PHPSchemaManager library:
<?php
require('PHPSchemaManager\PHPSchemaManager.php');
Register the PHPSchemaManager's autoloader:
<?php
\PHPSchemaManager\PHPSchemaManager::registerAutoload();
Setup the connection to your database (change the parameters to connect in your server)
<?php
// get the connection object
$connection = new \PHPSchemaManager\Connection();
// configure how to connect in the server
$connection->dbms = 'mysql';
$connection->username = 'username';
$connection->password = 'pasword';
$connection->hostname = '127.0.0.1';
$connection->port = '3306';
Get the manager instance
<?php
$manager = \PHPSchemaManager\PHPSchemaManager::getManager($connection);
Print tables from a Database in the screen (change the table name to you that exists in your database)
<?php
echo $manager->hasSchema('test')->printTxt();
You should see something like this
Tables from test (1 tables found) [synced]
table1 [synced]
id: serial(10), NOT NULL, _, unsigned [synced]
columnA: varchar(20), NULL, 'NULL', _ [synced]
columnB: char(5), NULL, 'NULL', _ [synced]
columnC: timestamp(0), NOT NULL, CURRENT_TIMESTAMP, _ [synced]
............................
indexes
PRIMARY: pk (id) [synced]
------------------------------
You can get more information about how to use this library in the Documentation
Items to be developed. Not necessarily in this order.
- [] Create a driver to connect with mysqli extension
- [] Create a driver to connect with PDO
- [] Integrate with sqlite
- [] Integrate with PostgreSQL
- Get information from Constraints
- [] Detect if the user have permission to work with a certain Schema
You can get more info in the PHPSchemaManager's Wiki
Ways to contribute to this library development:
- Fork this library and send your pull requests
- If you have design skills, a logo for this project will be most appreciated
- Do you know a free place to place the documentation for this project? I didn't like to so much the Wiki provided by Github.
You can see the report automatically generated by the scripts on autotest directory.
The PHPSchemaManager library is released under the MIT public license:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.