spoom-php / sql-mysql
MySQL support for Spoom Framework
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:spoom-extension
Requires
- php: ^7.2.0
- ext-mysqli: *
- spoom-php/composer: ^1.0.0
- spoom-php/core: @dev
- spoom-php/sql: @dev
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2025-04-12 11:04:46 UTC
README
Spoom is a collection of cooperative libraries (extensions), which you can use to "build" a framework that suits your needs.
About the MySQL
...
Installation
Install the latest version with
$ composer require spoom-php/sql-mysql
Usage
You can create connections and execute commands like this:
<?php require __DIR__ . '/vendor/autoload.php'; use Spoom\Sql\MySQL; // TODO ...you should create an application first... // create a (lazy) connection. You can force to connect with $connection->connect() $connection = new MySQL\Connection( '127.0.0.1:3306', 'root', '', 'test_database' ); // select some items from the table 'test', where foo is 'bar' $result = $connection->execute( 'SELECT title FROM test WHERE foo = {foo}', [ 'foo' => 'bar' ] ); // the statment can be created in builder style. The code below is equivalent with the above ->execute() but it's universal // $result = $connection->statement()->addTable( 'test' )->addField( 'title' )->addFilter( 'foo = {foo}' )->search( [ 'foo' => 'bar' ] ); // results used in a loop is equals with $result->getArrayList() foreach( $result as $i => $item ) { echo "{$i}. item's title is '{$item['title']}'\n"; }
You can also create connection from the configuration file located in the extension public directory.
The file spoom/spoom-sql-mysql/configuration/connection.json
should contain something like
{ "myfancyconnection": { "host": "127.0.0.1:3306", "user": "root", "password": "", "database": "test_database", "option": {} } }
and then you are able to do
<?php use Spoom\Sql\MySQL; // note that every instance from the same configuration name will be the exact same object $connection = MySQL\Connection::instance( 'myfancyconnection' );
License
The Spoom Framework is open-sourced software licensed under the MIT license.