PHP code example of tebe / pdo

1. Go to this page and download the library: Download tebe/pdo 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/ */

    

tebe / pdo example snippets


use tebe\pdo\PDO;
$db = new PDO('sqlite:database.sqlite');

$sql = "INSERT INTO fruits VALUES
(1, 'Banana', 'yellow', 250),
(2, 'Apple', 'red', 150),
(3, 'Pear', 'green', 150),
(4, 'Orange', 'orange', 300),
(5, 'Lime', 'green', 333),
(6, 'Lemon', 'yellow', 25),
(7, 'Peach', 'orange', 100),
(8, 'Cherry', 'red', 200)";
print $db->exec($sql);
// outputs 8

$sql = "SELECT name, color FROM fruits WHERE color = 'green' ORDER BY name";
print json_encode($db->query($sql)->fetchAll());
// outputs [{"name":"Lime","color":"green"},{"name":"Pear","color":"green"}]

$sql = "SELECT name FROM fruits WHERE color = ? ORDER BY name";
print json_encode($db->prepare($sql)->execute(['red'])->fetchAllColumn());
// outputs ["Apple","Cherry"]

$sql = "SELECT name, calories FROM fruits WHERE color = ? ORDER BY name";
print json_encode($db->run($sql, ['red'])->fetchAllPair());
// outputs {"Banana":250,"Lemon":25}

$sql = "SELECT color, name FROM fruits WHERE color IN (?) ORDER BY name";
print json_encode($db->run($sql, [['green', 'red']])->fetchAllGroup());
// outputs {"red":[{"name":"Apple"},{"name":"Cherry"}],"green":[{"name":"Lime"},{"name":"Pear"}]}

print $db->quote(['red', 'green', 'yellow']);
// outputs 'red', 'green', 'yellow'



public PDO::getWrappedPdo(): \PDO

public PDO::prepare(string $query, array $options = []): PDOStatement|false

public PDO::query(string $query, mixed ...$fetchModeArgs): PDOStatement|false

public PDO::quote(array|string|int|float|null $value, int $type = PDO::PARAM_STR): string|false

public PDO::run(string $sql, ?array $args = null): PDOStatement|false

public PDOStatement::__construct(\PDOStatement $stmt)

public PDOStatement::execute(?array $params = null): PDOStatement|false

public PDOStatement::fetchAffected(): int

public PDOStatement::fetchAssoc(): array|false

public PDOStatement::fetchBoth(): array|false

public PDOStatement::fetchInto(object $object): object|false

public PDOStatement::fetchNamed(): array|false

public PDOStatement::fetchNumeric(): array|false

public PDOStatement::fetchPair(): array|false

public PDOStatement::fetchAllAssoc(): array

public PDOStatement::fetchAllBoth(): array

public PDOStatement::fetchAllColumn(int $column = 0): array

public PDOStatement::fetchAllFunction(callable $callable): array

public PDOStatement::fetchAllGroup(int $style = 0): array

public PDOStatement::fetchAllNamed(): array

public PDOStatement::fetchAllNumeric(): array

public PDOStatement::fetchAllObject(string $class = 'stdClass', ?array $constructorArgs = null, int $style = 0): array

public PDOStatement::fetchAllPair(): array

public PDOStatement::fetchAllUnique(int $style = 0): array

public PDOParser::__construct(string $driver)

public PDOParser::rebuild(string $statement, array $values = []): array