Download the PHP package neat/database without Composer
On this page you can find all versions of the php package neat/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download neat/database
More information about neat/database
Files in neat/database
Informations about the package database
Neat Database components
Neat database components provide a clean and expressive API for accessing your databases. At its core is the Connection which uses a PDO instance underneath.
Getting started
To install this package, simply issue composer on the command line:
Then create a new database connection
Querying
Fetching information from the database is straightforward with the and methods. They both return a object that allows you to fetch and by calling its equally named methods.
Traversing results
In most cases, when you fetch a multi-row result, you'll want to iterate over the results row by row. This may seem trivial, but there are several ways to go about this.
Fetched results
To use a result multiple times (for example to count its rows and then return all the rows), you'll need to the result first. A live result wouldn't allow you to do this:
Manipulation
Because non-select queries never return a result, it wouldn't make sense to use the same result api either. Instead, the number of rows affected by your query would be nice to work with... which is exactly what the method gives you.
Notice how an insert with only 2 fields already gets quite long and unreadable. Because these data manipulation queries are often filled with data from arrays, it makes sense to use a specialized api for this purpose too.
Enter the , and methods. Like the method, these methods also return the number of rows affected.
Please note that the insert method does NOT return the last inserted id, instead you'll have to use the method.
Query building
To assist in writing queries within your code, you can use the query builder. It allows you to incrementally compose a query without having to worry about SQL syntax and concatenation yourself.
The query builder can be retrieved by calling the or method. By chaining method calls, you can interactively build your query and access the result by using the result api or convert the query to its string representation using a typecast or its get* methods.
The , and methods also return a query builder instance when you don't pass all their parameters.
Escaping and quoting
When the built-in query builder and placeholder substitution simply don't cut it anymore, you'll most likely end up concatenating your own SQL queries. The and methods allow you to safely embed literal values and identifiers into your own SQL statements.
Transactions and locking
If you want to run a set of database operations within a transaction, you can use the transaction method and pass your operations as a closure. When the closure returns, the transaction will be automatically committed. But if an exception is thrown, the transaction will rollback itself.