11<?php
22/*
33 PHP Mini MySQL Admin
4- (c) 2004-2016 Oleg Savchuk <osalabs@gmail.com> http://osalabs.com
4+ (c) 2004-2017 Oleg Savchuk <osalabs@gmail.com> http://osalabs.com
55
66 Light standalone PHP script for quick and easy access MySQL databases.
77 http://phpminiadmin.sourceforge.net
2727if (function_exists ('date_default_timezone_set ' )) date_default_timezone_set ('UTC ' );#required by PHP 5.1+
2828
2929//constants
30- $ VERSION ='1.9.161116 ' ;
30+ $ VERSION ='1.9.170117 ' ;
3131 $ MAX_ROWS_PER_PAGE =50 ; #max number of rows in select per one page
3232 $ D ="\r\n" ; #default delimiter for export
3333 $ BOM =chr (239 ).chr (187 ).chr (191 );
@@ -586,23 +586,24 @@ function dbq($s){
586586 return "' " .mysqli_real_escape_string ($ dbh ,$ s )."' " ;
587587}
588588
589- function db_query ($ sql , $ dbh1 =NULL , $ skiperr =0 ){
589+ function db_query ($ sql , $ dbh1 =NULL , $ skiperr =0 , $ resmod = MYSQLI_STORE_RESULT ){
590590 $ dbh1 =db_checkconnect ($ dbh1 , $ skiperr );
591- $ sth =mysqli_query ($ dbh1 , $ sql );
591+ $ sth =mysqli_query ($ dbh1 , $ sql, $ resmod );
592592 if (!$ sth && $ skiperr ) return ;
593593 if (!$ sth ) die ("Error in DB operation:<br> \n" .mysqli_error ($ dbh1 )."<br> \n$ sql " );
594594 return $ sth ;
595595}
596596
597597function db_array ($ sql , $ dbh1 =NULL , $ skiperr =0 , $ isnum =0 ){#array of rows
598- $ sth =db_query ($ sql , $ dbh1 , $ skiperr );
598+ $ sth =db_query ($ sql , $ dbh1 , $ skiperr, MYSQLI_USE_RESULT );
599599 if (!$ sth ) return ;
600600 $ res =array ();
601601 if ($ isnum ){
602602 while ($ row =mysqli_fetch_row ($ sth )) $ res []=$ row ;
603603 }else {
604604 while ($ row =mysqli_fetch_assoc ($ sth )) $ res []=$ row ;
605605 }
606+ mysqli_free_result ($ sth );
606607 return $ res ;
607608}
608609
@@ -852,14 +853,15 @@ function do_export(){
852853 ex_hdr ($ ctp ?$ ctp :'text/csv ' ,"$ t [0 ].csv $ aext " );
853854 if ($ DB ['chset ' ]=='utf8 ' ) ex_w ($ BOM );
854855
855- $ sth =db_query ("select * from ` $ t [0 ]` " );
856+ $ sth =db_query ("select * from ` $ t [0 ]` " , NULL , 0 , MYSQLI_USE_RESULT );
856857 $ fn =mysqli_field_count ($ dbh );
857858 for ($ i =0 ;$ i <$ fn ;$ i ++){
858859 $ m =mysqli_fetch_field ($ sth );
859860 ex_w (qstr ($ m ->name ).(($ i <$ fn -1 )?", " :"" ));
860861 }
861862 ex_w ($ D );
862863 while ($ row =mysqli_fetch_row ($ sth )) ex_w (to_csv_row ($ row ));
864+ mysqli_free_result ($ sth );
863865 }else {
864866 ex_start ('.sql ' );
865867 ex_hdr ($ ctp ?$ ctp :'text/plain ' ,"$ DB [db]" .(($ ct ==1 &&$ t [0 ])?". $ t [0 ]" :(($ ct >1 )?'. ' .$ ct .'tables ' :'' )).".sql $ aext " );
@@ -895,7 +897,7 @@ function do_export_table($t='',$tt='',$MAXI=838860){
895897 if ($ _REQUEST ['d ' ]&&$ tt !='VIEW ' ){//no dump for views
896898 $ exsql ='' ;
897899 ex_w ("/*!40000 ALTER TABLE ` $ t` DISABLE KEYS */; $ D " );
898- $ sth =db_query ("select * from ` $ t` " );
900+ $ sth =db_query ("select * from ` $ t` " , NULL , 0 , MYSQLI_USE_RESULT );
899901 while ($ row =mysqli_fetch_row ($ sth )){
900902 $ values ='' ;
901903 foreach ($ row as $ v ) $ values .=(($ values )?', ' :'' ).dbq ($ v );
@@ -904,6 +906,7 @@ function do_export_table($t='',$tt='',$MAXI=838860){
904906 ex_w ("INSERT INTO ` $ t` VALUES $ exsql; $ D " );$ exsql ='' ;
905907 }
906908 }
909+ mysqli_free_result ($ sth );
907910 if ($ exsql ) ex_w ("INSERT INTO ` $ t` VALUES $ exsql; $ D " );
908911 ex_w ("/*!40000 ALTER TABLE ` $ t` ENABLE KEYS */; $ D$ D " );
909912 }
@@ -922,7 +925,9 @@ function ex_start($ext){
922925 $ ex_tmpf =($ ex_issrv ?export_fname ($ DUMP_FILE ,true ).$ ext :tmp_name ()).'.gz ' ;
923926 if (!($ ex_gz =gzopen ($ ex_tmpf ,'wb9 ' ))) die ("Error trying to create gz tmp file " );
924927 }else {
925- if ($ ex_issrv ) $ ex_f =fopen (export_fname ($ DUMP_FILE ,true ).$ ext ,'wb ' );
928+ if ($ ex_issrv ) {
929+ if (!($ ex_f =fopen (export_fname ($ DUMP_FILE ,true ).$ ext ,'wb ' ))) die ("Error trying to create dump file " );
930+ }
926931 }
927932}
928933function ex_w ($ s ){
0 commit comments