Download the PHP package dcblogdev/pdo-wrapper without Composer

On this page you can find all versions of the php package dcblogdev/pdo-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pdo-wrapper

PDO Wrapper

This PDO wrapper, is a collection of methods for working with a database this includes selecting, inserting, updating and deleting records.

V2+ has been rewritten for the old docs please see V1 branch

Latest Version on Packagist Total Downloads

Logo

This PDO wrapper, is a collection of methods for working with a database this includes selecting, inserting, updating and deleting records.

V2+ has been rewritten for the old docs please see V1 branch

Upgrade from V1

Version 2 is now namespaced as Dcblogdev instead of Daveismyname

Also the methods get() and select() have been removed.

Instead of ::get() a new instance of the class used new Database($args)

Select has been replaced with ->rows() and ->row() or ->run()

Quick Reference

Install

Using composer include the repository by typing the following into a terminal

Set the DB credentials. Finally, create an instance of the classes.

Accessing PDO You can call getPdo()` to get access to PDO directly:

This allows to chain calls:

Querying

All queries use prepared statements, calling ->run() returns a PDO option that can be chained:

Select multiple records:

Select a single record:

Select multiple records using ->rows

Select single record using ->row

To select records based on user data instead of passing the data to the query directly use a prepared statement, this is safer and stops any attempt at sql injections.

Names placeholders

Annonomus placeholders

The above query will return the username from a users table where the id and email match. The id and email is passed seperartly in an array.

Instead of passing in an id and email to the query directly a placeholder is used :id and :email (or ? can be used) then an array is passed the keys in the array matches the placeholder and is bound, so the database will get both the query and the bound data.

Data returned from the query will be returns as an object this can be changed by passing a third param containing PDO::FETCH_ASSOC.

To use the object loop through it, a typical example:

Select Single Record

Using row() will return only a single result. Like rows it accepts params being passed in an array as a second argument.

Names placeholders

Anonymous placeholders

Another way to select a single record using the table and id by calling ->getById

Raw

A raw query is a query that does not run through a prepared statement and will execute the query passed directly. Useful when creating a table.

Count

To count records call the count method. This method expects the table name and column name (optional).

If the table has no column id

Insert

Data is inserted by calling the insert method it expects the table name followed by an array of key and values to insert in to the database.

The insert automatically returns the last inserted id by returning 'lastInsertId' to collect the id:

Updating

To update an existing record the update method is called. This method expects the table, array of data to update, and a second array containing the where condition.

Or:

Delete

To delete records call the delete method. This method expects the table name and an array of the where condition.

This will delete a single record to set the limit pass a third parameter containing the number to limit to or to remove the limit pass null as a third param.

Delete All

To delete all records for a given table

Delete by Id

To delete a record by its table and id

Delete Multiple In

To delete multiple records where ids are in a specific column, this uses WHERE id IN (4,5,6)

Truncate

To empty a table of all contents call the truncate method. Passing only the table name.


All versions of pdo-wrapper with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dcblogdev/pdo-wrapper contains the following files

Loading the files please wait ....