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.
composer require simpl/sql$db = new \Simpl\SQL('localhost', 'your-db-name', 'your-username', 'your-password');$config = [
'prefix' => 'mysql',
'host' => 'localhost',
'port' => 3306,
'dbname' => 'your-db-name',
'username' => 'your-username',
'password' => 'your-password'
];
$db = new \Simpl\SQL($config);$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
\PDOStatementobject you can then operate on as you normally would.
See https://simpl-php.com/components/sql for full documentation.
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
composer codensiffercomposer codefixer