Download the PHP package tommyknocker/pdo-database-class without Composer

On this page you can find all versions of the php package tommyknocker/pdo-database-class. 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-database-class

PDO-database-class

PHP PDO Wrapper which utilizes PDO and prepared statements


Table of Contents

Support Me

This software is developed during my free time and I will be glad if somebody will support me.

Everyone's time should be valuable, so please consider donating.

Donate with paypal

Installation

To utilize this class, first import PDODb.php into your project, and require it. PDODb requires PHP 5.5+ to work.

Installation with composer

It is also possible to install library via composer

Initialization

Simple initialization with utf8 charset set by default:

Advanced initialization:

table prefix, port and database charset params are optional. If no charset should be set charset, set it to null

Also it is possible to reuse already connected pdo object:

If no table prefix were set during object creation its possible to set it later with a separate call:

If you need to get already created pdo object from another class or function use

Insert Query

Simple example

Insert with functions use

Insert with on duplicate key update

Replace Query

Replace() method implements same API as insert();

Update Query

update() also support limit parameter:

Select Query

After any select/get function calls amount or returned rows is stored in $count variable

or select with custom columns set. Functions also could be used

or select just one row

or select one column value or function result

select one column value or function result from multiple rows:

You may use php 5.5+ generator feature with PDODb get(), rawQuery() methods just call useGenerator(true) method

Example:

Pagination

Use paginate() instead of get() to fetch paginated result

Defining a return type

To select a return type use setReturnType() method.

Running raw SQL queries

To avoid long if checks there are couple helper functions to work with raw query select results:

Get 1 row of results:

Get 1 column value as a string:

Get 1 column value from multiple rows:

More advanced examples:

Where / Having Methods

where(), orWhere(), having() and orHaving() methods allows you to specify where and having conditions of the query. All conditions supported by where() are supported by having() as well.

WARNING: In order to use column to column comparisons only raw where conditions should be used as column name or functions cant be passed as a bind variable.

Regular == operator with variables:

Regular == operator with column to column comparison:

BETWEEN / NOT BETWEEN:

IN / NOT IN:

OR CASE

NULL comparison:

Also you can use raw where conditions:

Or raw condition with variables:

Find the total number of rows matched. Simple pagination example:

Query Keywords

To add LOW PRIORITY | DELAYED | HIGH PRIORITY | IGNORE and the rest of the mysql keywords to INSERT (), REPLACE (), GET (), UPDATE (), DELETE() method or FOR UPDATE | LOCK IN SHARE MODE into SELECT ():

Also you can use an array of keywords:

Same way keywords could be used in SELECT queries as well:

Optionally you can use method chaining to call where multiple times without referencing your object over an over:

Delete Query

Ordering method

Order by values example:

If you are using setPrefix () functionality and need to use table names in orderBy() method make sure that table names are escaped with ``.

Grouping method

Join table products with table users with LEFT JOIN by tenantID

JOIN method

Properties sharing

Its is also possible to copy properties

Subqueries

Subquery init

Subquery init without an alias to use in inserts/updates/where Eg. (select * from users)

A subquery with an alias specified to use in JOINs . Eg. (select * from users) sq

Subquery in selects:

Subquery in inserts:

Subquery in joins:

EXISTS / NOT EXISTS condition

Has method

A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.

Helper methods

Get last executed SQL query: Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.

Check if table exists:

pdo::quote() wrapper:

Transaction helpers

Please keep in mind that transactions are working on innoDB tables. Rollback transaction if insert fails:

Error helpers

After you executed a query you have options to check if there was an error. You can get the MySQL error string or the error code for the last executed query.


All versions of pdo-database-class with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
ext-pdo Version *
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 tommyknocker/pdo-database-class contains the following files

Loading the files please wait ....