forked from aaronlord/mysqli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
95 lines (75 loc) · 2.26 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Some basic examples of how to use the class :)
*/
try {
include 'database/Mysqli_Database.php';
# New instance
$database = new Mysqli_Database;
$database->prepare("SELECT Body FROM Content WHERE ContentID = ? OR ContentID = ?;");
$database->execute(1, 2);
$page_content = $database->results();
# Num Rows
if($database->num_rows() > 0){
echo '<h3>$database->prepare(select_sql)->excecute(params,here)->results();<br/>'
.'$database->num_rows();</h3>'
.'<pre>'.print_r($page_content, 1).'</pre>'
.'<hr>';
}
###################################
# Inserts & Affected Rows
$rows_in = $database
->prepare("INSERT INTO Content(PageID, StyleID, Body) VALUES (?, ?, ?), (?, ?, ?);")
->execute(2, 1, 'Whaddup', 2, 2, 'Ribs')
->affected_rows();
# Insert ID
if($rows_in > 0){
echo '<h3>$database->prepare(insert_sql)->excecute(params,here)->affected_rows();</h3>'
.$rows_in.' row'.(count($rows_in) > 0 ? 's' : '')
.'<hr>'
.'<h3>$database->insert_id()</h3>'
.$database->insert_id()
.'<hr>';
}
###################################
# Query Delete & Affected Rows & Transaction
# ~ Side Note: This query hould really use prepare, but testing query method)
$database->start_transaction();
$rows_out = $database
->query("DELETE FROM Content WHERE PageID = 2;")
->affected_rows();
if($rows_out > 0){
echo '<h3>$database->query(delete_sql)->affected_rows();</h3>'
.$rows_out.' row'.(count($rows_out) > 0 ? 's' : '')
.'<hr>';
}
$database->rollback();
###################################
# Query Select
$all_content = $database
->query("SELECT Body FROM Content;")
->results();
if($database->num_rows() > 0){
echo '<h3>$database->query(select_sql)->results();<br/>'
.'$database->num_rows();</h3>'
.'<pre>'.print_r($all_content, 1).'</pre>'
.'<hr>';
}
###################################
# Transactions
$database->start_transaction();
$rows_out = $database
->query("DELETE FROM Content WHERE PageID = 2;")
->affected_rows();
if($rows_out > 0){
echo '<h3>$database->query(delete_sql)->affected_rows();</h3>'
.$rows_out.' row'.(count($rows_out) > 0 ? 's' : '')
.'<hr>';
}
$database->commit();
###################################
# Multiquery
}
catch(Exception $e){
echo $e->getMessage();
}