-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDbExample.php
More file actions
executable file
·44 lines (35 loc) · 1.07 KB
/
Copy pathDbExample.php
File metadata and controls
executable file
·44 lines (35 loc) · 1.07 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
<?php
require_once 'src/StaticPdo/Db.php';
use StaticPdo\Db;
// Set your connection info here
Db::setConnectionInfo('test', 'root', 'root*');
// Creating table for our testing
$query = "CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY,
username varchar(100) NOT NULL,
password varchar(100) NOT NULL,
status char(10)
);";
Db::execute($query);
// Let's create some data
$data = array(
array('name'=>'anis', 'pass'=>'ajaxray'),
array('name'=>'emran', 'pass'=>'phpfour'),
array('name'=>'raju', 'pass'=>'stylephp'),
);
foreach($data as $user){
Db::execute('INSERT INTO users(username, password) VALUES(:name, :pass)', $user);
}
// Retriving a field
$name = Db::getValue('SELECT username FROM users WHERE id = ?', 2);
echo 'Name of 2nd user : ' . $name . "<br />";
// Retriving a row
$row = Db::getRow('SELECT * FROM users WHERE id = ?', 1);
echo 'Row of 1st user : <pre>';
print_r($row);
echo "</pre> <br />";
// Retriving resultset
$result = Db::getResult('SELECT * FROM users limit 2');
echo '1st 3 users : <pre>';
print_r($result);
echo "</pre> <br />";