-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinsert.php
More file actions
77 lines (65 loc) · 2.13 KB
/
Copy pathinsert.php
File metadata and controls
77 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
use Dotenv\Dotenv;
use React\EventLoop\Loop;
use Saraf\QB\QueryBuilder\Core\DBFactory;
use Saraf\QB\QueryBuilder\Enums\OrderDirection;
use Saraf\QB\QueryBuilder\Exceptions\DBFactoryException;
include "vendor/autoload.php";
// Loop
$loop = Loop::get();
// Environments
$env = Dotenv::createImmutable(__DIR__ . "/../");
$env->load();
// Env Loader
$DB_NAME = $_ENV['DB_NAME'];
$DB_USER = $_ENV['DB_USER'];
$DB_PASS = $_ENV['DB_PASS'];
$DB_HOST = $_ENV['DB_HOST'];
$DB_PORT_READ = $_ENV['DB_PORT_READ'];
$DB_PORT_WRITE = $_ENV['DB_PORT_WRITE'];
try {
$dbFactory = new DBFactory(
$loop,
$DB_HOST,
$DB_NAME,
$DB_USER,
$DB_PASS,
$DB_PORT_WRITE,
$DB_PORT_READ,
5,
5,
2,
2
);
} catch (DBFactoryException $e) {
echo $e->getMessage();
exit(1);
}
$loop->run();
// INSERT INTO Customers (CustomerName, ContactName, Address) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21');
$dbFactory->getQueryBuilder()
->insert()
->into("Customers")
->setColumns(["CustomerName", "ContactName", "Address"])
->addRow(['Cardinal', 'Tom B. Erichsen', 'Skagen 21'])
->compile()
->getQuery()
->then(function ($result) {
echo "Excepted: INSERT INTO Customers (CustomerName, ContactName, Address) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21')" . PHP_EOL;
echo "Actual: " . $result['query'] . PHP_EOL . PHP_EOL;
});
// INSERT INTO Customers (CustomerName, ContactName, Address) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21'),('MamadReza', 'Ola Sr', 'Samoel');
$dbFactory->getQueryBuilder()
->insert()
->into("Customers")
->setColumns(["CustomerName", "ContactName", "Address"])
->addRows([
['Cardinal', 'Tom B. Erichsen', 'Skagen 21'],
['MamadReza', 'Ola Sr', 'Samoel'],
])
->compile()
->getQuery()
->then(function ($result) {
echo "Excepted: INSERT INTO Customers (CustomerName, ContactName, Address) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21'),('MamadReza', 'Ola Sr', 'Samoel')" . PHP_EOL;
echo "Actual: " . $result['query'] . PHP_EOL . PHP_EOL;
});