simpl / sql
A dead-simple layer on top of PDO to make PDO setup and querying simpler
Requires
- php: >=5.1.0
- ext-pdo: *
Requires (Dev)
- phpunit/phpunit: ^5
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ^3.4 || ^5.1
This package is auto-updated.
Last update: 2024-11-26 15:04:14 UTC
README
A dead-simple layer on top of PDO to make PDO setup and querying simpler
This component makes it easy to make and execute SQL statements with PDO.
You can run parameterized queries in a single step instead of doing separate prepare and execute statements.
This will automatically convert your query to a prepared statement with parameterized queries to prevent nasty SQL injection attacks.
Installation
composer require simpl/sql
Usage
Connecting to the database.
Basic connection
$db = new \Simpl\SQL('localhost', 'your-db-name', 'your-username', 'your-password');
Connection with configuration array.
$config = [ 'prefix' => 'mysql', 'host' => 'localhost', 'port' => 3306, 'dbname' => 'your-db-name', 'username' => 'your-username', 'password' => 'your-password' ]; $db = new \Simpl\SQL($config);
Running a SELECT query with parameters.
$res = $db->query('select * from test where foo = ? or bar = ?', [$foo, $bar]);
Since this is just a wrapper around PDO, you'll get back a
\PDOStatement
object you can then operate on as you normally would.
See https://simpl-php.com/components/sql for full documentation.
Coding Standards
This library uses PHP_CodeSniffer to ensure coding standards are followed.
I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion.
To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml
Codesniffer
composer codensiffer
Codefixer
composer codefixer