6161$ db ->close ();
6262///////////////////////////////////////////////////////////////////////////////////////////
6363
64-
6564// Example 2
6665// Connection example
6766///////////////////////////////////////////////////////////////////////////////////////////
132131$ db ->close ();
133132///////////////////////////////////////////////////////////////////////////////////////////
134133
135-
136134// Example 5
137135// Faster select exmaple (fetch query to array)
138136///////////////////////////////////////////////////////////////////////////////////////////
144142$ db ->close ();
145143///////////////////////////////////////////////////////////////////////////////////////////
146144
147-
148145// Exmaple 6
149146// Multi results
150147///////////////////////////////////////////////////////////////////////////////////////////
180177$ db ->close ();
181178///////////////////////////////////////////////////////////////////////////////////////////
182179
183-
184180// Example 7
185181// Rows, Cols num
186182///////////////////////////////////////////////////////////////////////////////////////////
199195$ db ->close ();
200196///////////////////////////////////////////////////////////////////////////////////////////
201197
202-
203198// Example 8
204199// Count rows
205200///////////////////////////////////////////////////////////////////////////////////////////
224219$ db ->close ();
225220///////////////////////////////////////////////////////////////////////////////////////////
226221
227-
228222// Example 9
229223// Array to insert
230224///////////////////////////////////////////////////////////////////////////////////////////
258252$ db ->close ();
259253///////////////////////////////////////////////////////////////////////////////////////////
260254
261-
262255// Example 10
263256// Next AutoIncrement
264257///////////////////////////////////////////////////////////////////////////////////////////
340333///////////////////////////////////////////////////////////////////////////////////////////
341334
342335// Example 14
336+ // Basic Table Operation
337+ ///////////////////////////////////////////////////////////////////////////////////////////
338+ $ db = new MySQL_wrapper (HOST , USER , PASS , DB );
339+ // Connect
340+ $ db ->connect ();
341+
342+ // Rename table
343+ $ db ->renameTable (array ('old_table_name ' => 'new_table_name ' ));
344+ // Swap table names
345+ $ db ->renameTable (array ('table1 ' => 'tmp_table ' , 'table2 ' => 'table1 ' , 'tmp_table ' => 'table1 ' ));
346+
347+ // Copy table (with data included)
348+ $ db ->copyTable ('table ' , 'table_copy ' );
349+ // Copy table structure
350+ $ db ->copyTable ('table ' , 'table_copy2 ' , FALSE );
351+
352+ // Truncate table (empty)
353+ $ db ->truncateTable ('table_copy2 ' );
354+
355+ // Drop one table
356+ $ db ->dropTable ('table_copy2 ' );
357+ // Drop multiple tables
358+ $ db ->dropTable (array ('table_copy ' , 'table_copy2 ' ));
359+
360+ // Close connection
361+ $ db ->close ();
362+ ///////////////////////////////////////////////////////////////////////////////////////////
363+
364+ // Example 15
365+ // Get database size
366+ ///////////////////////////////////////////////////////////////////////////////////////////
367+ $ db = new MySQL_wrapper (HOST , USER , PASS , DB );
368+
369+ // Connect
370+ $ db ->connect ();
371+ /** Data Base size in B / KB / MB / GB / TB
372+ * @param string $sizeIn - Size in B / KB / MB / GB / TB
373+ * @param integer $round - Round on decimals
374+ * @param resource $link - Link identifier
375+ * @return - Size in B / KB / MB / GB / TB
376+ */
377+ // function getDataBaseSize($sizeIn = 'MB', $round = 2, $link = 0)
378+ echo '<hr /><pre>Database size is: ' , $ db ->getDataBaseSize ('mb ' , 2 ), ' MB</pre> ' ;
379+ // Close connection
380+ $ db ->close ();
381+ ///////////////////////////////////////////////////////////////////////////////////////////
382+
383+ // Example 16
343384// Loging queries and errors
344385///////////////////////////////////////////////////////////////////////////////////////////
345386$ db = new MySQL_wrapper (HOST , USER , PASS , DB );
358399$ db ->close ();
359400///////////////////////////////////////////////////////////////////////////////////////////
360401
361- // Example 15
402+ // Example 17
362403// Export Table to CSV
363404///////////////////////////////////////////////////////////////////////////////////////////
364405$ db = new MySQL_wrapper (HOST , USER , PASS , DB );
390431$ db ->close ();
391432///////////////////////////////////////////////////////////////////////////////////////////
392433
393- // Example 16
434+ // Example 18
435+ // Query to CSV
436+ ///////////////////////////////////////////////////////////////////////////////////////////
437+ $ db = new MySQL_wrapper (HOST , USER , PASS , DB );
438+
439+ // Connect
440+ $ db ->connect ();
441+ /** Export query to CSV file.
442+ * @param string $sql - MySQL Query
443+ * @param string $file - CSV File path
444+ * @param string $delimiter - COLUMNS TERMINATED BY (Default: ',')
445+ * @param string $enclosure - OPTIONALLY ENCLOSED BY (Default: '"')
446+ * @param string $escape - ESCAPED BY (Default: '\')
447+ * @param string $newLine - New line delimiter (Default: \n)
448+ * @param boolean $showColumns - Columns names in first line
449+ * @param resource $link - Link identifier
450+ * @return - File path
451+ */
452+ // function query2CSV($sql, $file, $delimiter = ',', $enclosure = '"', $escape = '\\', $newLine = '\n', $showColumns = TRUE, $link = 0)
453+ $ path = $ db ->query2CSV ('select * from `table` limit 10 ' , 'test-query2csv.csv ' );
454+ echo '<hr /><pre>Query exported to CSV file: ' , $ path , '</pre> ' ;
455+ // Close connection
456+ $ db ->close ();
457+ ///////////////////////////////////////////////////////////////////////////////////////////
458+
459+ // Example 19
394460// Import CSV to Table
395461///////////////////////////////////////////////////////////////////////////////////////////
396462$ db = new MySQL_wrapper (HOST , USER , PASS , DB );
417483$ db ->close ();
418484///////////////////////////////////////////////////////////////////////////////////////////
419485
420- // Example 17
486+ // Example 20
421487// Import CSV to Table
422488///////////////////////////////////////////////////////////////////////////////////////////
423489$ db = new MySQL_wrapper (HOST , USER , PASS , DB );
439505// Close connection
440506$ db ->close ();
441507
442- // Example 18
508+ // Example 21
443509// String Replace Table Columns
444510///////////////////////////////////////////////////////////////////////////////////////////
445511$ db = new MySQL_wrapper (HOST , USER , PASS , DB );
471537// function strReplace($table, $columns, $search, $replace, $where = NULL, $limit = 0, $link = 0)
472538// Close connection
473539$ db ->close ();
474-
475- // Example 20
476- // Basic Table Operation
477- ///////////////////////////////////////////////////////////////////////////////////////////
478- $ db = new MySQL_wrapper (HOST , USER , PASS , DB );
479- // Connect
480- $ db ->connect ();
481-
482- // Rename table
483- $ db ->renameTable (array ('old_table_name ' => 'new_table_name ' ));
484- // Swap table names
485- $ db ->renameTable (array ('table1 ' => 'tmp_table ' , 'table2 ' => 'table1 ' , 'tmp_table ' => 'table1 ' ));
486-
487- // Copy table (with data included)
488- $ db ->copyTable ('table ' , 'table_copy ' );
489- // Copy table structure
490- $ db ->copyTable ('table ' , 'table_copy2 ' , FALSE );
491-
492- // Truncate table (empty)
493- $ db ->truncateTable ('table_copy2 ' );
494-
495- // Drop one table
496- $ db ->dropTable ('table_copy2 ' );
497- // Drop multiple tables
498- $ db ->dropTable (array ('table_copy ' , 'table_copy2 ' ));
499-
500- // Close connection
501- $ db ->close ();
502-
503- ///////////////////////////////////////////////////////////////////////////////////////////
504-
505- // Example 21
506- // Get database size
507- ///////////////////////////////////////////////////////////////////////////////////////////
508- $ db = new MySQL_wrapper (HOST , USER , PASS , DB );
509-
510- // Connect
511- $ db ->connect ();
512- /** Data Base size in B / KB / MB / GB / TB
513- * @param string $sizeIn - Size in B / KB / MB / GB / TB
514- * @param integer $round - Round on decimals
515- * @param resource $link - Link identifier
516- * @return - Size in B / KB / MB / GB / TB
517- */
518- // function getDataBaseSize($sizeIn = 'MB', $round = 2, $link = 0)
519- echo '<hr /><pre>Database size is: ' , $ db ->getDataBaseSize ('mb ' , 2 ), ' MB</pre> ' ;
520- // Close connection
521- $ db ->close ();
0 commit comments