1- PHP_MySQL_wrapper
2- =================
1+ PHP MySQL Wrapper Class
2+ =======================
33
44This class implements a generic MySQL database access wrapper.
55
@@ -183,8 +183,8 @@ $db->connect();
183183$db->query('SELECT * FROM `table`');
184184
185185// Int affected rows
186- if($db->affected > 0){
187- while($row = $db->fetchArray()){
186+ if ($db->affected > 0) {
187+ while ($row = $db->fetchArray()) {
188188 // Result
189189 print_r($row);
190190 }
@@ -216,8 +216,8 @@ $params['limit'] = 5;
216216$db->query("SELECT * FROM `table` WHERE `firstname` LIKE '@name%' AND `surname` LIKE '%@lname%' OR `id` = @id LIMIT @limit;", $params);
217217
218218// Int affected rows
219- if($db->affected > 0){
220- while($row = $db->fetchArray()){
219+ if ($db->affected > 0) {
220+ while ($row = $db->fetchArray()) {
221221 // Print result row
222222 print_r($row);
223223 }
@@ -324,16 +324,16 @@ $r1 = $db->query('SELECT * FROM `table`');
324324$r2 = $db->query('SELECT * FROM `table` LIMIT 2');
325325
326326// Result 1 data
327- if($db->numRows($r1)){
328- while($row = $db->fetchArray($r1)){
327+ if ($db->numRows($r1)) {
328+ while ($row = $db->fetchArray($r1)) {
329329 // Print rows
330330 print_r($row);
331331 }
332332}
333333
334334// Result 2 data
335- if($db->numRows($r2)){
336- while($row = $db->fetchArray($r2)){
335+ if ($db->numRows($r2)) {
336+ while ($row = $db->fetchArray($r2)) {
337337 // Print rows
338338 print_r($row);
339339 }
@@ -393,8 +393,9 @@ echo "Count all: {$count}, Count today: {$count2}";
393393 * @param string $table - Table name
394394 * @param string $where - WHERE Clause
395395 * @return integer or false
396+ *
397+ * function countRows($table, $where = NULL);
396398 */
397- // $db->countRows($table, $where = NULL)
398399
399400// Close connection
400401$db->close();
@@ -428,8 +429,9 @@ echo "Last insert id is: {$insert_id}";
428429 * @param boolean $ingore - INSERT IGNORE (row won't actually be inserted if it results in a duplicate key)
429430 * @param string $duplicateupdate - ON DUPLICATE KEY UPDATE (The ON DUPLICATE KEY UPDATE clause can contain multiple column assignments, separated by commas.)
430431 * @return insert id or false
432+ *
433+ * function arrayToInsert($table, $data, $ignore = FALSE, $duplicateupdate = NULL);
431434 */
432- // $db->arrayToInsert($table, $data, $ignore = FALSE, $duplicateupdate = NULL);
433435
434436// Close connection
435437$db->close();
@@ -490,7 +492,7 @@ $data['date'] = 'now()';
490492
491493
492494$db->arrayToUpdate('table', $data, "`id` = {$insert_id}");
493- if($db->affected > 0){
495+ if ($db->affected > 0) {
494496 echo "Updated: {$db->affected} row(s).";
495497}
496498
@@ -502,8 +504,9 @@ if($db->affected > 0){
502504 * @param integer $limit - Limit offset
503505 * @param resource $link - link identifier
504506 * @return number of updated rows or false
507+ *
508+ * function arrayToUpdate($table, $data, $where = NULL, $limit = 0, $link = 0);
505509 */
506- // $db->arrayToUpdate($table, $data, $where = NULL, $limit = 0, $link = 0);
507510
508511// Close connection
509512$db->close();
@@ -563,7 +566,7 @@ $db->connect();
563566// Delete row
564567$db->deleteRow('table', "`id` = {$insert_id}");
565568
566- if($db->affected > 0) {
569+ if ($db->affected > 0) {
567570 echo "Deleted: {$db->affected} row(s).";
568571}
569572// More options
@@ -573,8 +576,9 @@ if($db->affected > 0) {
573576 * @param integer $limit - Limit offset
574577 * @param resource $link - link identifier
575578 * @return number of deleted rows or false
579+ *
580+ * function deleteRow($table, $where = NULL, $limit = 0, $link = 0);
576581 */
577- // $db->deleteRow($table, $where = NULL, $limit = 0, $link = 0);
578582
579583// Close connection
580584$db->close();
@@ -614,8 +618,9 @@ $db->exportTable2CSV('table', 'test_files/test-4.txt', '*', 'id < 8', '1,5');
614618 * @param string $newLine - New line detelimiter (Default: \n)
615619 * @param boolean $showColumns - Columns names in first line
616620 * @return number of inserted rows or false
621+ *
622+ * function exportTable2CSV($table, $file, $columns = '*', $where = NULL, $limit = 0, $delimiter = ',', $enclosure = '"', $escape = '\\', $newLine = '\n', $showColumns = TRUE);
617623 */
618- // $db->exportTable2CSV($table, $file, $columns = '*', $where = NULL, $limit = 0, $delimiter = ',', $enclosure = '"', $escape = '\\', $newLine = '\n', $showColumns = TRUE);
619624
620625// Close connection
621626$db->close();
@@ -643,8 +648,9 @@ $path = $db->query2CSV('select * from `table` limit 2,2', 'test_files/test-query
643648 * @param string $newLine - New line delimiter (Default: \n)
644649 * @param boolean $showColumns - Columns names in first line
645650 * @return - File path
651+ *
652+ * function query2CSV($sql, $file, $delimiter = ',', $enclosure = '"', $escape = '\\', $newLine = '\n', $showColumns = TRUE);
646653 */
647- // function query2CSV($sql, $file, $delimiter = ',', $enclosure = '"', $escape = '\\', $newLine = '\n', $showColumns = TRUE);
648654
649655// Close connection
650656$db->close();
@@ -672,8 +678,9 @@ $db->importCSV2Table('test_files/test-1.txt', 'table');
672678 * @param string $getColumnsFrom - Get Columns Names from (file or table) - this is important if there is update while inserting (Default: file)
673679 * @param string $newLine - New line detelimiter (Default: \n)
674680 * @return number of inserted rows or false
681+ *
682+ * function importCSV2Table($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\n');
675683 */
676- // $db->importCSV2Table($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\n');
677684
678685// Close connection
679686$db->close();
@@ -703,8 +710,9 @@ $db->importUpdateCSV2Table('test_files/countrylist.csv', 'csv_to_table_test', ',
703710 * @param string $getColumnsFrom - Get Columns Names from (file or table) - this is important if there is update while inserting (Default: file)
704711 * @param string $newLine - New line detelimiter (Default: \n)
705712 * @return number of inserted rows or false
713+ *
714+ * function importUpdateCSV2Table($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\n');
706715 */
707- // $db->importUpdateCSV2Table($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\n');
708716
709717// Close connection
710718$db->close();
@@ -734,8 +742,9 @@ $db->createTableFromCSV('test_files/countrylist1.csv', 'csv_to_table_test_no_col
734742 * @param string $getColumnsFrom - Get Columns Names from (file or generate) - this is important if there is update while inserting (Default: file)
735743 * @param string $newLine - New line delimiter (Default: \n)
736744 * @return number of inserted rows or false
737- */
738- // function createTableFromCSV($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\r\n');
745+ *
746+ * function createTableFromCSV($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\r\n');
747+ */
739748
740749// Close connection
741750$db->close();
@@ -761,8 +770,9 @@ $xml = $db->query2XML('select * from `table` limit 10', 'items', 'item');
761770 * @param string $rootElementName - root element name
762771 * @param string $childElementName - child element name
763772 * @return string - XML
773+ *
774+ * function query2XML($query, $rootElementName, $childElementName, $file = NULL);
764775 */
765- // function query2XML($query, $rootElementName, $childElementName, $file = NULL);
766776
767777// Close connection
768778$db->close();
@@ -789,8 +799,9 @@ $db->transaction($queries);
789799/** Transaction
790800 * @param array $qarr - Array with Queries
791801 * @link http://dev.mysql.com/doc/refman/5.0/en/commit.html
802+ *
803+ * function transaction($qarr = array());
792804 */
793- // $db->transaction($qarr = array());
794805
795806// Close connection
796807$db->close();
@@ -833,8 +844,9 @@ $db->strReplace('*', '*', 'search', 'replace');
833844 * @param string $where - WHERE Clause
834845 * @param integer $limit - Limit offset
835846 * @return integer - Affected rows
847+ *
848+ * function strReplace($table, $columns, $search, $replace, $where = NULL, $limit = 0);
836849 */
837- // function strReplace($table, $columns, $search, $replace, $where = NULL, $limit = 0);
838850
839851// Close connection
840852$db->close();
@@ -903,8 +915,9 @@ $db->connect();
903915 * @param integer $round - Round on decimals
904916 * @param resource $link - Link identifier
905917 * @return - Size in B / KB / MB / GB / TB
918+ *
919+ * function getDataBaseSize($sizeIn = 'MB', $round = 2, $link = 0);
906920 */
907- // function getDataBaseSize($sizeIn = 'MB', $round = 2, $link = 0);
908921
909922echo 'Database size is: ', $db->getDataBaseSize('mb', 2), ' MB';
910923
@@ -947,17 +960,19 @@ $time = '2014-06-25 14:26:03';
947960 * @param string $rev_table - Revision table (origin table)
948961 * @param string $id_field - Unique field name
949962 * @param datetime - Revision time
963+ *
964+ * function createTableFromRevisionTime($table, $rev_table, $id_field, $time);
950965 */
951- // $db->createTableFromRevisionTime($table, $rev_table, $id_field, $time);
952966
953967$db->createTableFromRevisionTime('rev-table' . '-' . $time, 'rev-table', 'id', $time);
954968
955969/** Restore table from current revision time
956970 * @param string $table - New table name
957971 * @param string $id_field - Unique field name
958972 * @param datetime - Revision time
973+ *
974+ * function restoreTableFromRevisionTime($table, $id_field, $time);
959975 */
960- //$db->restoreTableFromRevisionTime($table, $id_field, $time);
961976
962977$db->restoreTableFromRevisionTime('rev-table', 'id', $time);
963978
0 commit comments