-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
51 lines (43 loc) · 1.51 KB
/
example.php
File metadata and controls
51 lines (43 loc) · 1.51 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
<?php
// SQLMethods example/unit test
// Use your preferred class loading mechanism
require ('SQLMethods.class.php');
// Obtain a PDO connection in your preferred way
$conn = new PDO (
'pgsql:host=<host>;port=<port>;dbname=<database name>',
'<user>', '<password>',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => FALSE]
);
/* There are different ways to build SQLMethod instances and inport SQL files
// Use a single SQL file
$dbgw = new SQLMethods('sql/example.sql', $conn);
// Use many SQL files
$dbgw = new SQLMethods;
$dbgw -> connection($conn);
$dbgw -> import('sql/none.sql');
$dbgw -> import('sql/named.sql');
$dbgw -> import('sql/positional.sql');
$dbgw -> import('sql/value.sql');
*/
// Use many SQL files w/ method chaining
$dbgw = SQLMethods::createInstance($conn)
-> import('sql/none.sql')
-> import('sql/named.sql')
-> import('sql/positional.sql')
-> import('sql/value.sql');
// call a method with no arguments
$result = $dbgw -> Ruffus();
echo SQLMethods::dump_rs($result);
echo PHP_EOL.PHP_EOL;
// call a method with named arguments
$result = $dbgw -> Buster([':hi' => 17, ':lo' => 15]);
echo SQLMethods::dump_rs($result);
echo PHP_EOL.PHP_EOL;
// call a method with positional arguments
$result = $dbgw -> Gracie(18, 20);
echo SQLMethods::dump_rs($result);
echo PHP_EOL.PHP_EOL;
// call a method with positional arguments that returns a single value
$result = $dbgw -> ISOTime('P2D');
echo $result;
echo PHP_EOL.PHP_EOL;