Skip to content

Commit ca06ddd

Browse files
author
Radovan Janjic
committed
Update desc
1 parent 3a94bdc commit ca06ddd

File tree

3 files changed

+58
-42
lines changed

3 files changed

+58
-42
lines changed

MySQL_wrapper.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Projectname: PHP MySQL Wrapper Class
55
* Version: 1.6
66
* Author: Radovan Janjic <[email protected]>
7+
* Link: https://github.com/uzi88/PHP_MySQL_wrapper
78
* Last modified: 11 08 2014
89
* Copyright (C): 2008-2014 IT-radionica.com, All Rights Reserved
910
*

README.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PHP_MySQL_wrapper
2-
=================
1+
PHP MySQL Wrapper Class
2+
=======================
33

44
This 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

909922
echo '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

example.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
$db->close();
9292

9393
// Connect with new link
94-
$db->connect(true);
94+
$db->connect(TRUE);
9595
//
9696
// Connection 3 queries
9797
//
@@ -132,12 +132,12 @@
132132
$db->connect();
133133

134134
// MySQL query
135-
$db->query('SELECT * FROM `table`');
135+
$db->query('SELECT * FROM `table`;');
136136

137137
// Int affected rows
138-
if($db->affected){
138+
if ($db->affected) {
139139
echo "<hr /><strong>Example 4 ( fetch row - array)</strong><pre>";
140-
while($row = $db->fetchArray()){
140+
while ($row = $db->fetchArray()) {
141141
print_r($row);
142142
}
143143
echo "</pre>";
@@ -163,9 +163,9 @@
163163
$db->query("SELECT * FROM `table` WHERE `firstname` LIKE '@name%' AND `surname` LIKE '%@lname%' OR `id` = @id LIMIT @limit;", $params);
164164

165165
// Int affected rows
166-
if($db->affected){
166+
if ($db->affected) {
167167
echo "<hr /><strong>Example 4 ( fetch row - array)</strong><pre>";
168-
while($row = $db->fetchArray()){
168+
while ($row = $db->fetchArray()) {
169169
print_r($row);
170170
}
171171
echo "</pre>";
@@ -228,15 +228,15 @@
228228

229229
// Result 1 data
230230
echo "<hr /><strong>Example 6 (multi results)</strong><br> Result 1:<pre>";
231-
if($db->numRows($r1)){
232-
while($row = $db->fetchArray($r1)){
231+
if ($db->numRows($r1)) {
232+
while ($row = $db->fetchArray($r1)) {
233233
print_r($row);
234234
}
235235
}
236236
echo "</pre>\nResult 2:\n<pre>";
237237
// Result 2 data
238-
if($db->numRows($r2)){
239-
while($row = $db->fetchArray($r2)){
238+
if ($db->numRows($r2)) {
239+
while ($row = $db->fetchArray($r2)) {
240240
print_r($row);
241241
}
242242
}
@@ -256,7 +256,7 @@
256256
$db = MySQL_wrapper::getInstance(MySQL_HOST, MySQL_USER, MySQL_PASS, MySQL_DB);
257257
$db->connect();
258258

259-
$db->query('SELECT * FROM `table`');
259+
$db->query('SELECT * FROM `table`;');
260260

261261
$cols = $db->numFields();
262262
$rows = $db->numRows();
@@ -371,7 +371,7 @@
371371
$data['date'] = 'now()';
372372

373373
$db->arrayToUpdate('table', $data, "`id` = {$insert_id}");
374-
if($db->affected){
374+
if ($db->affected) {
375375
echo "<hr /><strong>Example 11 (array to update)</strong><br />Updated: {$db->affected} row(s).<br />";
376376
}
377377

@@ -415,7 +415,7 @@
415415
$db->connect();
416416

417417
$db->deleteRow('table', "`id` = {$insert_id}");
418-
if($db->affected){
418+
if ($db->affected) {
419419
echo "<hr><strong>Example 12 (delete row)</strong><br />Deleted: {$db->affected} row(s).<br />";
420420
}
421421
// More options
@@ -677,7 +677,7 @@
677677
* @param array $qarr - Array with Queries
678678
* @link http://dev.mysql.com/doc/refman/5.0/en/commit.html
679679
*/
680-
// $db->transaction($qarr = array())
680+
// function transaction($qarr = array())
681681
// Close connection
682682
$db->close();
683683
///////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)