@@ -14,13 +14,17 @@ class mysql {
14
14
15
15
/**
16
16
* Connect to the database.
17
- * @param str server
18
- * @param str username
19
- * @param str password
20
- */
21
- function connect ($ server , $ username , $ password ) {
22
- if ($ this ->db = @mysql_pconnect ($ server , $ username , $ password )) {
23
- return TRUE ;
17
+ * @param str[] config
18
+ */
19
+ function connect ($ config ) {
20
+ if ($ this ->db = @mysql_pconnect (
21
+ $ config ['server ' ],
22
+ $ config ['username ' ],
23
+ $ config ['password ' ]
24
+ )) {
25
+ if ($ this ->select_db ($ config ['database ' ])) {
26
+ return TRUE ;
27
+ }
24
28
}
25
29
return FALSE ;
26
30
}
@@ -48,7 +52,7 @@ function select_db($database) {
48
52
* @return resource A resultset resource
49
53
*/
50
54
function getColumns ($ table ) {
51
- return mysql_query (sprintf ('SHOW COLUMNS FROM %s ' , $ table ), $ this ->db );
55
+ return mysql_query (sprintf ('SHOW COLUMNS FROM %s ' , $ table ), $ this ->db );
52
56
}
53
57
54
58
/**
@@ -58,7 +62,7 @@ function getColumns($table) {
58
62
* @return resource A resultset resource
59
63
*/
60
64
function getRow ($ table , $ where ) {
61
- return mysql_query (sprintf ('SELECT * FROM %s WHERE %s ' , $ table , $ where ));
65
+ return mysql_query (sprintf ('SELECT * FROM %s WHERE %s ' , $ table , $ where ));
62
66
}
63
67
64
68
/**
@@ -68,15 +72,15 @@ function getRow($table, $where) {
68
72
* @return resource A resultset resource
69
73
*/
70
74
function getTable ($ primary , $ table ) {
71
- return mysql_query (sprintf ('SELECT %s FROM %s ' , $ primary , $ table ));
75
+ return mysql_query (sprintf ('SELECT %s FROM %s ' , $ primary , $ table ));
72
76
}
73
77
74
78
/**
75
79
* Get the tables in a database.
76
80
* @return resource A resultset resource
77
81
*/
78
82
function getDatabase () {
79
- return mysql_query ('SHOW TABLES ' );
83
+ return mysql_query ('SHOW TABLES ' );
80
84
}
81
85
82
86
/**
@@ -87,7 +91,7 @@ function getDatabase() {
87
91
* @return bool
88
92
*/
89
93
function updateRow ($ table , $ values , $ where ) {
90
- return mysql_query (sprintf ('UPDATE %s SET %s WHERE %s ' , $ table , $ values , $ where ));
94
+ return mysql_query (sprintf ('UPDATE %s SET %s WHERE %s ' , $ table , $ values , $ where ));
91
95
}
92
96
93
97
/**
@@ -107,7 +111,7 @@ function insertRow($table, $names, $values) {
107
111
* @return resource A resultset resource
108
112
*/
109
113
function deleteRow ($ table , $ where ) {
110
- return mysql_query (sprintf ('DELETE FROM %s WHERE %s ' , $ table , $ where ));
114
+ return mysql_query (sprintf ('DELETE FROM %s WHERE %s ' , $ table , $ where ));
111
115
}
112
116
113
117
/**
@@ -125,7 +129,7 @@ function escape($string) {
125
129
* @return str[] An array of the fields and values from the next row in the resultset
126
130
*/
127
131
function row ($ resource ) {
128
- return mysql_fetch_assoc ($ resource );
132
+ return mysql_fetch_assoc ($ resource );
129
133
}
130
134
131
135
/**
@@ -150,7 +154,7 @@ function numAffected() {
150
154
* @return int The last insert ID
151
155
*/
152
156
function lastInsertId () {
153
- return mysql_insert_id ();
157
+ return mysql_insert_id ();
154
158
}
155
159
156
160
}
0 commit comments