1
1
<?php
2
2
/*
3
3
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
5
5
6
6
Light standalone PHP script for quick and easy access MySQL databases.
7
7
http://phpminiadmin.sourceforge.net
27
27
if (function_exists ('date_default_timezone_set ' )) date_default_timezone_set ('UTC ' );#required by PHP 5.1+
28
28
29
29
//constants
30
- $ VERSION ='1.9.161116 ' ;
30
+ $ VERSION ='1.9.170117 ' ;
31
31
$ MAX_ROWS_PER_PAGE =50 ; #max number of rows in select per one page
32
32
$ D ="\r\n" ; #default delimiter for export
33
33
$ BOM =chr (239 ).chr (187 ).chr (191 );
@@ -586,23 +586,24 @@ function dbq($s){
586
586
return "' " .mysqli_real_escape_string ($ dbh ,$ s )."' " ;
587
587
}
588
588
589
- function db_query ($ sql , $ dbh1 =NULL , $ skiperr =0 ){
589
+ function db_query ($ sql , $ dbh1 =NULL , $ skiperr =0 , $ resmod = MYSQLI_STORE_RESULT ){
590
590
$ dbh1 =db_checkconnect ($ dbh1 , $ skiperr );
591
- $ sth =mysqli_query ($ dbh1 , $ sql );
591
+ $ sth =mysqli_query ($ dbh1 , $ sql, $ resmod );
592
592
if (!$ sth && $ skiperr ) return ;
593
593
if (!$ sth ) die ("Error in DB operation:<br> \n" .mysqli_error ($ dbh1 )."<br> \n$ sql " );
594
594
return $ sth ;
595
595
}
596
596
597
597
function 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 );
599
599
if (!$ sth ) return ;
600
600
$ res =array ();
601
601
if ($ isnum ){
602
602
while ($ row =mysqli_fetch_row ($ sth )) $ res []=$ row ;
603
603
}else {
604
604
while ($ row =mysqli_fetch_assoc ($ sth )) $ res []=$ row ;
605
605
}
606
+ mysqli_free_result ($ sth );
606
607
return $ res ;
607
608
}
608
609
@@ -852,14 +853,15 @@ function do_export(){
852
853
ex_hdr ($ ctp ?$ ctp :'text/csv ' ,"$ t [0 ].csv $ aext " );
853
854
if ($ DB ['chset ' ]=='utf8 ' ) ex_w ($ BOM );
854
855
855
- $ sth =db_query ("select * from ` $ t [0 ]` " );
856
+ $ sth =db_query ("select * from ` $ t [0 ]` " , NULL , 0 , MYSQLI_USE_RESULT );
856
857
$ fn =mysqli_field_count ($ dbh );
857
858
for ($ i =0 ;$ i <$ fn ;$ i ++){
858
859
$ m =mysqli_fetch_field ($ sth );
859
860
ex_w (qstr ($ m ->name ).(($ i <$ fn -1 )?", " :"" ));
860
861
}
861
862
ex_w ($ D );
862
863
while ($ row =mysqli_fetch_row ($ sth )) ex_w (to_csv_row ($ row ));
864
+ mysqli_free_result ($ sth );
863
865
}else {
864
866
ex_start ('.sql ' );
865
867
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){
895
897
if ($ _REQUEST ['d ' ]&&$ tt !='VIEW ' ){//no dump for views
896
898
$ exsql ='' ;
897
899
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 );
899
901
while ($ row =mysqli_fetch_row ($ sth )){
900
902
$ values ='' ;
901
903
foreach ($ row as $ v ) $ values .=(($ values )?', ' :'' ).dbq ($ v );
@@ -904,6 +906,7 @@ function do_export_table($t='',$tt='',$MAXI=838860){
904
906
ex_w ("INSERT INTO ` $ t` VALUES $ exsql; $ D " );$ exsql ='' ;
905
907
}
906
908
}
909
+ mysqli_free_result ($ sth );
907
910
if ($ exsql ) ex_w ("INSERT INTO ` $ t` VALUES $ exsql; $ D " );
908
911
ex_w ("/*!40000 ALTER TABLE ` $ t` ENABLE KEYS */; $ D$ D " );
909
912
}
@@ -922,7 +925,9 @@ function ex_start($ext){
922
925
$ ex_tmpf =($ ex_issrv ?export_fname ($ DUMP_FILE ,true ).$ ext :tmp_name ()).'.gz ' ;
923
926
if (!($ ex_gz =gzopen ($ ex_tmpf ,'wb9 ' ))) die ("Error trying to create gz tmp file " );
924
927
}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
+ }
926
931
}
927
932
}
928
933
function ex_w ($ s ){
0 commit comments