Definition in file db.php.
Go to the source code of this file.
Functions | |
| build_insert_sql_from_array ($array, $pre= ', $post= ', $quote=FALSE, $value_getter=get_identity_value') | |
| Creates string which you can pass to INSERT SQL command as VALUES based on an array. | |
| exists ($sql) | |
| get_id_value ($obj) | |
| Helper for build_insert_sql_from_array(). | |
| get_identity_value ($obj) | |
| Helper for build_insert_sql_from_array(). | |
| insert ($sql) | |
| For INSERT with autoincremented PK. | |
| insert_unique ($sql, $errormsg) | |
| Executes INSERT or UPDATE SQL statement. | |
| one_line_query ($sql, $errormsg=Error.') | |
| Performs SQL query that return only one record. | |
| query ($sql) | |
| update ($sql) | |
| For INSERT/UPDATE/DELETE. | |
|
||||||||||||||||||||||||
|
Creates string which you can pass to INSERT SQL command as VALUES based on an array. This is useful for adding multiple values in one SQL command. Example: $a = array('a', 'b', 'c'); $s = build_insert_sql_from_array($a, '1', '2', TRUE); $s == "(1, 'a', 2),(1, 'b', 2),(1, 'c', 2)";
db_query("INSERT INTO table VALUES $s");
Definition at line 257 of file db.php. 00257 {
00258 if ($pre):
00259 $pre = "$pre,";
00260 endif;
00261 if ($post):
00262 $post = ",$post";
00263 endif;
00264 $sqllines = array();
00265 foreach ($array as $obj):
00266 $value = $value_getter($obj);
00267 if ($quote):
00268 $sqllines[] = "($pre '$value' $post)";
00269 else:
00270 $sqllines[] = "($pre $value $post)";
00271 endif;
00272 endforeach;
00273 return join(',', $sqllines);
00274 }
|
|
|
Definition at line 150 of file db.php. 00150 {
00151 $db = new Db();
00152 $result = $db->query($sql);
00153
00154 /*
00155 This clearly shows how is PHP badly designed language.
00156 You cannot simply write
00157 $count = $result->fetch_row()[0];
00158 You even cannot write
00159 $count = ($result->fetch_row())[0];
00160 */
00161 $count = $result->fetch_row();
00162 $count = $count[0];
00163
00164 $db->close();
00165 if ($count == 1):
00166 return TRUE;
00167 endif;
00168 return FALSE;
00169 }
|
|
|
Helper for build_insert_sql_from_array().
Definition at line 228 of file db.php. 00228 {
00229 return $obj->get_id();
00230 }
|
|
|
Helper for build_insert_sql_from_array().
Definition at line 220 of file db.php. 00220 {
00221 return $obj;
00222 }
|
|
|
For INSERT with autoincremented PK.
Definition at line 208 of file db.php. 00208 {
00209 $db = new Db();
00210 $db->query($sql);
00211 $id = $db->insert_id;
00212 $db->close();
00213 return $id;
00214 }
|
|
||||||||||||
|
Executes INSERT or UPDATE SQL statement.
Definition at line 129 of file db.php. 00129 {
00130 $db = new Db();
00131 try {
00132 $db->query($sql);
00133 }
00134 catch (Exception $e) {
00135 if ($db->errno == 1062):
00136 throw new Exception($errormsg);
00137 else:
00138 throw $e;
00139 endif;
00140 }
00141 $db->close();
00142 }
|
|
||||||||||||
|
Performs SQL query that return only one record.
Definition at line 182 of file db.php. 00182 {
00183 $db = new Db();
00184 $result = $db->query($sql);
00185 $obj = $result->fetch_object();
00186 if (!$obj):
00187 throw new RecordNotFound($errormsg);
00188 endif;
00189 return $obj;
00190 }
|
|
|
Definition at line 117 of file db.php. Referenced by Db::__construct(), and Db::query(). 00117 {
00118 $q = new DbQuery($sql);
00119 return $q;
00120 }
|
|
|
For INSERT/UPDATE/DELETE.
Definition at line 196 of file db.php. 00196 {
00197 $db = new Db();
00198 $db->query($sql);
00199 $db->close();
00200 }
|
1.4.2