phpMySQLi_jacket is a wrapper to interface PHP with MySQL using the mysqli extension in PHP
- Features
- Documentation
- Downloads
- Write parametrized queries easily (prepare, bind, execute)
- Call non parametrized queries (for MySQL cache)
- Reduce the amount of code you have to write
- Analyze your queries
- And more..
Example usage of phpMySQLi_jacket
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
|
include 'phpMySQLi_jacket.class.php';
// use your own class, if wanna
class my_db extends phpMySQLi_jacket {
}
// minimum options, see source for more
$opts = array(
'host' => '127.0.0.1',
'username' => 'accounting',
'password' => '1234',
'database' => 'sales',
);
$db = new my_db($opts);
// simple select; query is not prepared, thus cachable by MySQL
$result = $db->select('SELECT alias, name FROM users WHERE alias = 'bob'');
while ($row = $result->fetch_assoc()) {
echo $row.' '.$row['name'].'<br/>';
}
echo '<hr/>';
// select with parameterization ie auto escaping of user input
// ? are placeholders for the values
// ss is the data type of the column; s = string, i = integer, see source for more
// array() holds the actual values
$result = $db->select('SELECT alias, name FROM users WHERE alias IN (?,?)', 'ss', array('bob','donna'));
while ($row = $result->fetch_object()) {
echo $row->alias.' '.$row->name.'<br/>';
}
echo '<hr/>';
// call a stored proc with parameterization
// results returned as an array, optionally
$sql = "CALL qtrSales(?)";
$rows = $db->proc($sql, 'i', array(4));
foreach ($rows as $row) {
echo $row['sales'].'<br/>';
}
echo '<hr/>';
// update query; could have also used the method update() which is an alias of execute()
$nbr_affected_rows = $db->execute("UPDATE users SET name = ? WHERE alias = 'bob'", 's', array('Bobby'));
echo $nbr_affected_rows;
echo '<hr/>';
// insert query; could have also used the method insert() which is an alias of execute()
$insert_id = $db->execute("INSERT INTO users (name, alias) VALUES (?, ?)", 'ss', array('Bobby', 'bob'));
echo $insert_id;
echo '<hr/>';
// output some stats about the MySQL server and client
$db->output_about();
// output the number of queries, explain statments ran against SELECTs, and total process time
$db->output_stats();
[/code]
|
Version: 0.1
Released: 2010-06-17
Download from Google Code:
Download or Download from local mirror:
Download