Download the PHP package garkavenkov/db-connector without Composer
On this page you can find all versions of the php package garkavenkov/db-connector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package db-connector
db-connector
DBConnect - Class-wrapper for PDO Class.
Installation
Use Composer
composer require garkavenkov/db-connector
Usage
Initialization
There are two ways to set database configuration parameters. First one is through constants.
Second one is through an associative array as a parameter in getInstance() method.
By default database parameter db_port
is empty, thus database driver uses its own default port. If you need to use specific port number you must define it as a constant
or as an associative array.
Methods
exec(string $sql)
Executes an SQL statement and returns the number of affected rows
Output:
query(string $sql)
Executes an SQL statement and returns an DBConnect object with result set as a PDOStatement object.
For example, this code set UTF8 code
Output:
After this method you can chain another method that works with PDOStatement object. For example getRow()
getRow($fetch_style = null)
Fetches a row from a result set. The $fetch_style
determines how PDO returns the row. By default uses PDO::FETCH_ASSOC
Output:
For getting result as an object use PDO::FETCH_OBJ
Output:
getRows($fetch_style = null)
Returns an array containing all of the result set rows. Result depends on $fetch_style
. By
default uses PDO::FETCH_ASSOC
prepare(string $sql, $standalone = false)
Prepares an SQL statement for execution and returns DBConnect object that contains prepared PDOstatement.
Output:
If you set $standalone=true
, this method returns a PDOstatement object rather than DBConnect object.
Output
execute(array $params, $stmt = null)
Executes a prepared statement.
If you set $stmt
parameter this method will execute standalone prepared statement.
getLastInsertedId()
Returns Id from last inserted record
Output:
getFieldValue(string $field_name)
Returns value of particular field
Output:
getFieldValues(string $field_name)
Returns an array that contains values from given field
Output:
rowCount()
Returns the number of rows affected by the last SQL statement.
Output:
closeCursor()
Closes cursor for next execution.
getAvailableDrivers()
Returns an array of available PDO drivers.
Output: