Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/auraphp/aura.sqlschema
Independent schema discovery tools for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.
https://github.com/auraphp/aura.sqlschema
aura database pdo php sql
Last synced: 20 days ago
JSON representation
Independent schema discovery tools for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.
- Host: GitHub
- URL: https://github.com/auraphp/aura.sqlschema
- Owner: auraphp
- License: bsd-2-clause
- Created: 2013-09-27T18:12:26.000Z (over 11 years ago)
- Default Branch: 2.x
- Last Pushed: 2016-04-29T13:48:57.000Z (over 8 years ago)
- Last Synced: 2024-12-20T06:07:11.009Z (20 days ago)
- Topics: aura, database, pdo, php, sql
- Language: PHP
- Size: 447 KB
- Stars: 40
- Watchers: 14
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Aura.SqlSchema
Provides facilities to read table names and table columns from a database
using a [PDO](http://php.net/PDO) connection.## Foreword
### Installation
This library requires PHP 5.3 or later; we recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies.
It is installable and autoloadable via Composer as [aura/sqlschema](https://packagist.org/packages/aura/sqlschema).
Alternatively, [download a release](https://github.com/auraphp/Aura.SqlSchema/releases) or clone this repository, then require or include its _autoload.php_ file.
### Quality
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/auraphp/Aura.SqlSchema/badges/quality-score.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.SqlSchema/)
[![Code Coverage](https://scrutinizer-ci.com/g/auraphp/Aura.SqlSchema/badges/coverage.png?b=develop-2)](https://scrutinizer-ci.com/g/auraphp/Aura.SqlSchema/)
[![Build Status](https://travis-ci.org/auraphp/Aura.SqlSchema.png?branch=develop-2)](https://travis-ci.org/auraphp/Aura.SqlSchema)To run the unit tests at the command line, issue `phpunit` at the package root. (This requires [PHPUnit][] to be available as `phpunit`.)
[PHPUnit]: http://phpunit.de/manual/
This library attempts to comply with [PSR-1][], [PSR-2][], and [PSR-4][]. If
you notice compliance oversights, please send a patch via pull request.[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md### Community
To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our [Google Group](http://groups.google.com/group/auraphp), follow [@auraphp on Twitter](http://twitter.com/auraphp), or chat with us on #auraphp on Freenode.
## Getting Started
### Instantiation
Instantiate a driver-specific schema object with a matching
[PDO](http://php.net/PDO) instance:```php
```
### Fetching Table Lists
To get a list of tables in the database, issue `fetchTableList()`:
```php
fetchTableList();
foreach ($tables as $table) {
echo $table . PHP_EOL;
}
?>
```### Fetching Column Information
To get information about the columns in a table, issue `fetchTableCols()`:
```php
fetchTableCols('table_name');
foreach ($cols as $name => $col) {
echo "Column $name is of type "
. $col->type
. " with a size of "
. $col->size
. PHP_EOL;
}
?>
```Each column description is a `Column` object with the following properties:
- `name`: (string) The column name
- `type`: (string) The column data type. Data types are as reported by the database.
- `size`: (int) The column size.
- `scale`: (int) The number of decimal places for the column, if any.
- `notnull`: (bool) Is the column marked as `NOT NULL`?
- `default`: (mixed) The default value for the column. Note that sometimes
this will be `null` if the underlying database is going to set a timestamp
automatically.- `autoinc`: (bool) Is the column auto-incremented?
- `primary`: (bool) Is the column part of the primary key?