PHPackages                             craftblue/simple-sql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. craftblue/simple-sql

ActiveLibrary[Database &amp; ORM](/categories/database)

craftblue/simple-sql
====================

SimpleSql is a wrapper around PHP's PDO and is intended to be an easy to use drop-in for your projects. It abstracts away the atrocities of querying by using common methods while still giving you full control of your queries

9264[1 issues](https://github.com/cballou/SimpleSql/issues)PHP

Since May 18Pushed 10y ago1 watchersCompare

[ Source](https://github.com/cballou/SimpleSql)[ Packagist](https://packagist.org/packages/craftblue/simple-sql)[ RSS](/packages/craftblue-simple-sql/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

About
-----

[](#about)

SimpleSql is a wrapper around PHP's PDO and is intended to be an easy to use drop-in for your projects. It abstracts away the atrocities of querying by using common methods while still giving you full control of your queries.

A number of the atrocities SimpleSql handles are:

- Automatically retries failed queries up to 3 times
- Automatic reconnection attempt on the MySQL `2006, mysql server has gone away` error
- Fixing potential issues with `PDO::MYSQL_ATTR_USE_BUFFERED_QUERY` by automatically closing cursors before new calls are made

Querying and Prepared Statements
--------------------------------

[](#querying-and-prepared-statements)

One of the primary benefits of using PDO is you get out of box support of prepared statements. This really boils down to speed and security (prevention of SQL injection). Other than the `query()` method, all other methods utilize prepared statements. These methods include: `fetchRow()`, `fetchRows()`, `insert()`, `update()`, and `delete()`.

Below you will find two examples of how you use prepared statements:

#### Named Bindings

[](#named-bindings)

This method of generating your queries is ideal because it is easily changeable if something changes in your code. You specify bound parameters to be replaced using the `:parameter` syntax in your SQL string. Your data array must be an associative array of key/val pairs where the keys match your named parameters in the SQL.

```
