Skip to content

Commit 7fa8eae

Browse files
author
Karel Wintersky
committed
1.99.0
- v 2.0 Release candidate - PHP8 version - Changed class names - Implements PDO
1 parent 9767ef1 commit 7fa8eae

22 files changed

+1001
-1341
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Как использовать
2+
3+
```php
4+
require_once __DIR__ . '/vendor/autoload.php';
5+
6+
$config = new \Arris\Database\Config();
7+
8+
$config->setUsername('wombat')
9+
->setPassword('wombatsql')
10+
->setDatabase('47news')
11+
->setSlowQueryThreshold(15);
12+
13+
$pdo = $config->connect();
14+
15+
// ИЛИ
16+
17+
$pdo = new \Arris\Database\Connector($config);
18+
19+
$sth = $pdo->prepare("SELECT COUNT(*) FROM articles");
20+
$sth->execute();
21+
var_dump($sth->fetchColumn());
22+
23+
// или
24+
25+
$sth = $pdo->query("SELECT COUNT(*) FROM articles");
26+
var_dump($sth->fetchColumn());
27+
28+
// debug
29+
var_dump($pdo->stats()->getSlowQueries());
30+
31+
var_dump($pdo->stats()->getLastQuery());
32+
```
33+
34+
# Опции
35+
36+
Как установить, например, `PDO::ATTR_EMULATE_PREPARES`?
37+
38+
```php
39+
$config = new \Arris\Database\Config();
40+
$config->option(PDO::ATTR_EMULATE_PREPARES, true);
41+
```
42+
43+
# Статистика
44+
45+
- getQueryCount - количество простых запросов (query)
46+
- getPreparedQueryCount - количество подготовленных запросов (prepare, execute)
47+
- getTotalQueryCount - количество всего запросов (подготовленные и простые)
48+
- getTotalQueryTime - время, потраченное всеми запросами
49+
- getQueries - список запросов
50+
- getSlowQueries - список медленных запросов
51+
- getLastQuery - статистика по последнему запросу
52+
- reset - обнуление статистики

composer.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "karelwintersky/arris.database",
3-
"description": "Arris µFramework database wrapper",
3+
"description": "Arris µFramework database lazy connector",
44
"type": "library",
55
"license": "MIT",
66
"authors": [
@@ -15,23 +15,13 @@
1515
"platform-check": false
1616
},
1717
"require": {
18-
"php": ">=7.4 | 8.*",
18+
"php": "^8.2",
1919
"ext-pdo": "*",
2020
"psr/log": "*"
2121
},
22-
"require-dev": {
23-
"predis/predis": "^2.0",
24-
"vlucas/phpdotenv": "^3.3",
25-
"symfony/var-dumper": "^5.4",
26-
"php-sage/sage": "^1.3",
27-
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5",
28-
"php-coveralls/php-coveralls": "^1.1",
29-
"rector/rector": "^1.1"
30-
},
3122
"suggest": {
3223
"karelwintersky/arris.entity": "Arris µFramework: Entity Types",
33-
"karelwintersky/arris.helpers": "Arris µFramework: helpers",
34-
"ajur-media/fluentpdo": "^1"
24+
"karelwintersky/arris.helpers": "Arris µFramework: helpers"
3525
},
3626
"autoload": {
3727
"psr-4": {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Arris\Database;
4+
5+
use Psr\Log\LoggerInterface;
6+
7+
interface ConfigInterface
8+
{
9+
public function __construct(array $connection_config = [], ?LoggerInterface $logger = null);
10+
11+
public function setDriver(?string $driver):self;
12+
public function setHost(string $host = 'localhost'):self;
13+
public function setPort(mixed $port): self;
14+
15+
public function setUsername(?string $username):self;
16+
public function setPassword(?string $password):self;
17+
public function setDatabase(?string $database):self;
18+
19+
public function setCredentials(?string $username, ?string $password): self;
20+
21+
public function setCharset(?string $charset): self;
22+
public function setCharsetCollation(?string $charset_collation):self;
23+
24+
public function option(int $option, mixed $value): self;
25+
public function driverOption(int $option, mixed $value): self;
26+
27+
public function getDSN(): string;
28+
public function getUsername(): ?string;
29+
public function getPassword(): ?string;
30+
public function getOptions(): array;
31+
32+
public function connect();
33+
34+
public function setSlowQueryThreshold(mixed $value, bool $as_ms = true):self;
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Arris\Database;
4+
5+
use PDO;
6+
use PDOStatement;
7+
8+
interface ConnectorInterface
9+
{
10+
public function __construct(Config $config);
11+
12+
public function prepare(string $query, array $options = []): PDOStatement|false;
13+
public function query($query, $fetchMode = PDO::ATTR_DEFAULT_FETCH_MODE, ...$fetchModeArgs): PDOStatement|false;
14+
public function exec(string $statement): int|false;
15+
16+
public function lastInsertId(?string $name = null): string|false;
17+
18+
public function beginTransaction(): bool;
19+
public function inTransaction(): bool;
20+
public function commit(): bool;
21+
public function rollBack(): bool;
22+
23+
public function errorCode(): ?string;
24+
public function errorInfo(): array;
25+
26+
public function setAttribute(int $attribute, mixed $value): bool;
27+
public function getAttribute(int $attribute): mixed;
28+
public function quote(string $string, int $type = PDO::PARAM_STR): string|false;
29+
30+
public function stats():Stats;
31+
}

interfaces/Database/DBConfigInterface.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

interfaces/Database/DBHelperInterface.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

interfaces/Database/DBMultiConnectorInterface.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

interfaces/Database/DBPoolInterface.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)