-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathprepare.php
45 lines (36 loc) · 1.43 KB
/
prepare.php
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
<?php
/**
* This file is part of the tarantool/client package.
*
* (c) Eugene Leonovich <gen.work@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
require __DIR__.'/../bootstrap.php';
$client = create_client();
ensure_server_version_at_least('2.3.1-68', $client);
$client->execute('DROP TABLE IF EXISTS users');
$client->execute('CREATE TABLE users ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50))');
$stmt = $client->prepare('INSERT INTO users VALUES(null, ?)');
for ($i = 1; $i <= 100; ++$i) {
$stmt->execute("name_$i");
// You can also use executeSelect() and executeUpdate(), e.g.:
// $lastInsertIds = $stmt->executeUpdate("name_$i")->getAutoincrementIds();
}
$stmt->close();
/**
* SEQSCAN keyword is explicitly allowing to use seqscan:
* https://github.com/tarantool/tarantool/commit/77648827326ad268ec0ffbcd620c2371b65ef2b4
* It was introduced in Tarantool 2.11.0-rc1. If compat.sql_seq_scan_default set to "new"
* (default value since 3.0), query returns error when trying to scan without keyword.
*/
$scanQuery = server_version_at_least('2.11.0-rc1', $client)
? 'SELECT COUNT("id") AS "cnt" FROM SEQSCAN users'
: 'SELECT COUNT("id") AS "cnt" FROM users';
$result = $client->executeQuery($scanQuery);
printf("Result: %s\n", json_encode($result[0]));
/* OUTPUT
Result: {"cnt":100}
*/