-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
74 lines (60 loc) · 1.76 KB
/
index.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
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
<?php
require_once dirname(__FILE__).'/src/SimplePDOWrapper.php';
// Declare database configuration.
$conf = array(
'database' => 'your_db_name',
'user' => 'root',
'password' => 'toor',
'host' => 'localhost'
);
$SimplePDOWrapper = new SimplePDOWrapper($conf);
// Switch database with setDatabase() method and pass credentials in $conf array.
$conf = array(
'database' => 'another_db',
'user' => 'root',
'password' => 'toor',
'host' => 'localhost'
);
// Will return boolean.
if (!$SimplePDOWrapper->setDatabase($conf))
{
// Watch for errors through @var $errors.
// Errors is an array with code and message.
throw new Exception($SimplePDOWrapper->errors['message'], $SimplePDOWrapper->errors['code']);
}
// After saving you will receive the last saved entity.
$save = array(
'id' => 10,
'username' => 'jaime.ziga@gmail.com',
'password' => 'thypassword',
'name' => 'John Doe'
);
$user_saved = $SimplePDOWrapper->save('users', $save);
// When updating it will only return true or false.
$update = array(
'name' => 'Adrián Zúñiga'
);
$updated = $SimplePDOWrapper->update('users', $update, array(
'conditions' => array(
'id' => $user_saved['id']
)
));
// Watching errors
if (!$updated)
{
throw new Exception($SimplePDOWrapper->errors['message'], $SimplePDOWrapper->errors['code']);
}
// For now conditions only has basic clause.
$options = array(
'conditions' => array(),
'limit' => 10,
'fields' => array('id', 'username', 'password', 'name'),
'order' => array('id DESC')
);
// This findOne will return the one entity array or null.
$user = $SimplePDOWrapper->findOne('users', $options);
// And findAll will return null or an array of STDClass objects.
$users = $SimplePDOWrapper->findAll('users', $options);
var_dump($user);
var_dump($users);
var_dump($updated);