1. Go to this page and download the library: Download bentools/pdoextended library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bentools / pdoextended example snippets
$ids = $cnx->sqlColumn("SELECT Id FROM table WHERE CreationDate BETWEEN ? AND ?", ['2013-01-01', '2013-06-01']);
$id = $cnx->sqlValue("SELECT Id FROM table WHERE Id = ?", [35]);
$id = $cnx->sqlValue("SELECT Id FROM table WHERE Id = ?", 35); // You don't need an array if you just have 1 value to bind
$row = $cnx->sqlRow("SELECT * FROM table WHERE Name LIKE :Name AND Id >= :Id", ['Name' => 'foo%', 'Id' => 22]);
$stmt = $cnx->prepare("SELECT Id FROM table WHERE CreationDate BETWEEN ? AND ?");
$ids = $stmt->sqlColumn(['2013-01-01', '2013-06-01']); // Fetches Ids in an indexed array
var_dump($stmt->debug()->preview()); // SELECT Id FROM table WHERE CreationDate BETWEEN '2013-01-01' AND '2013-06-01'
var_dump($stmt->debug()->duration); // 0.004
$ids = [2, 5, 8, 24, 26];
try {
$rows = $cnx->sqlArray("SELECT * FROM table WHERE Id IN (".PDOStatementExtended::PlaceHolders($ids).")", $ids);
}
catch (StmtException $e) {
var_dump($e->getStmt()->queryString); // SELECT * FROM table WHERE Id IN (?, ?, ?, ?, ?)
var_dump($e->getStmt()->preview()); // SELECT * FROM table WHERE Id IN (2, 5, 8, 24, 26)
}
// Also works with strings with automatic quote wrapping
$dates = ['2013-01-01', '2013-06-01'];
try {
$rows = $cnx->sqlArray("SELECT * FROM table WHERE CreationDate IN (".PDOStatementExtended::PlaceHolders($dates).")", $dates);
}
catch (StmtException $e) {
var_dump($e->getStmt()->queryString); // SELECT * FROM table WHERE CreationDate IN (?, ?)
var_dump($e->getStmt()->preview()); // SELECT * FROM table WHERE CreationDate IN ('2013-01-01', '2013-06-01')
}
$cnx->sqlArray("SELECT * WHERE foo = ?", 'bar'); // "SELECT * WHERE foo = ?" string is prepared and transformed to a PDOStatementExtended object
$cnx->sqlArray("SELECT * WHERE foo = ?", 'baz'); // "SELECT * WHERE foo = ?" now matches an existing PDOStatementExtended object previously stored and doesn't have to be prepared again
$cnx->storeStmts(false); // or true
$pdo = new \PDO('mysql:host=localhost', 'user', 'password');
$cnx = PDOExtended\PDOExtended::NewInstanceFromPdo($pdo);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.