PHP code example of addiks / phpsql
1. Go to this page and download the library: Download addiks/phpsql 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/ */
addiks / phpsql example snippets
use Addiks\PHPSQL\PDO\PDO;
use Addiks\PHPSQL\Result\ResultWriter;
# create a new database in memory
$pdo = new PDO('inmemory:some_example_database');
$pdo->query("
CREATE TABLE foo(
id INT PRIMARY KEY AUTO_INCREMENT,
bar VARCHAR(32),
baz DECIMAL(3,12)
)
");
$pdo->query("
INSERT INTO foo
(bar, baz)
VALUES
(?, ?)
", ['Lorem ipsum', 3.1415]);
$result = $pdo->query("SELECT * FROM foo");
$rows = $result->fetchAll(PDO::FETCH_NUM);
foreach ($rows as $row) {
var_dump($row);
}
# Creates an ASCII-art-table representing a result.
echo new ResultWriter($pdo->query('DESCRIBE foo')->getResult());