|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-06-02 21:53 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon May 25 04:00:01 2026 UTC |
Description: ------------ <p> mysql_fetch_array is works ::</p> <?php function db_operations( $uH , $uN , $uP , $q ){ $logs=array(); $logs_ok=array();$logs_error=array(); # login to mysql $log=""; $log .= "Connection to DataBase Server = "; $link=@mysql_connect($uH, $uN, $uP); //mysql_connect("$uH", "$uN", "$uP") or //die("Could not connect: " . mysql_error()); if ( $link ){ $link=mysql_connect($uH, $uN, $uP); $log .="OK!;"; $logs_ok[]=$log; }else{ //$log .= "(".mysql_error ($link); $log .="FAILED, possible SERVER ERROR / wrong user name / wrong password;"; $logs_error[]=$log; } $logs[]=$log; // if(func_num_args()>4){ ## Select database Name $uDB=func_get_arg(4); $log = ""; $log .= "Get () DB = "; if(count($logs_error)==0){ $log="Connection to DB = "; if ( mysql_select_db("$uDB") ) { $log .="($uDB) OK!;"; $logs_ok[]=$log; }else{ $log .= mysql_errno($link)." : ".mysql_error($link);; //$log .="Database is NOT exists;"; $logs_error[]=$log; } $logs[]=$log; } } // if(count($logs_error)==0){ # testing query $log="Running Command ($q) = "; if ( $result = mysql_query("$q") ) { $log .="OK;"; $logs_ok[]=$log; }else{ $log .="ERROR;"; $log = mysql_errno($link)." : ".mysql_error($link);; $logs_error[]=$log; } $logs[]=$log; } // if(count($logs_error)==0){ ## looking for fields $log="Fetching Fields = "; if ( $field_total=mysql_num_fields($result) ) { $fields=array(); for($field_no=0 ; $field_no < $field_total ; $field_no++){ $field_name=mysql_field_name($result, $field_no); $fields[]=$field_name; //print("<br>");print("(".$field_name.")");print("<br>"); } $log .="OK -> total = ($field_total);"; $logs_ok[]=$log; }else{ $log .="ERROR;"; $logs_warning[]=$log; } $logs[]=$log; } $log="Extracting Data = "; if(count($logs_error)==0){ $datas=array(); while ($data_array = mysql_fetch_array($result, MYSQL_ASSOC)) { ## // ERROR WAS HERE !!! \\ ## $dataNew_lable=""; if (isset($data_new)){unset($data_new);};$data_new=array(); for ($field_at=0 ; $field_at < count($fields) ; $field_at++){ $data_field=$fields[$field_at]; $data_new[$data_field]=$data_array[$data_field]; } $datas[]=$data_new; } $log .="OK -> total = (".count($datas).");"; $logs_ok[]=$log; }else{ $log .="ERROR;"; $log = mysql_errno($link)." : ".mysql_error($link);; $logs_error[]=$log; } $logs[]=$log; if(count($logs_error)==0){ $effectedRows=mysql_affected_rows(); } # $return=array(); if(count($logs_error)==0){ $return[]=true; }else{ $return["logs"]=$effectedRows; $return["affected_rows"]=$effectedRows; $return["datas"]=$datas; $return["created by"]="dRAke RafE"; } return $return; mysql_free_result($result);unset($result); mysql_close($link);unset($link); unset($datas); ;} ?> <?php $tabel1="family"; $uH="localhost";$uN="drake"."";$uP="drake".""; $uDB="drake_relationship".""; $uCmd="SELECT * FROM `$tabel1`;"; $connect=db_operations($uH , $uN , $uP , $uCmd , $uDB ); print ("(<pre>");print_r($connect);print ("</pre>)<br>\n");## PHP Printed Functions Here ##; ?> <p>This code WILL NOT WORK IF we writing : (Preview included in <strong>Reproduce code</strong>)</p> <?php if (!function_exists("db_operations")){ function db_operations( $uH , $uN , $uP , $q ){ $logs=array(); ## CODE IS SAME ; ## };}; ## all (my) user defined function prefix starting ||if (!function_exists("function_name")|| works!!! except this ("db_operations") ?> <?php ## ## THIS IS DIFFERENT PROBLEMS ## is there any way to returning variable instead printing "Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'xxx@localhost' (Using password: YES)"# ?> Reproduce code: --------------- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\web\works\drake\2.php on line 77 ## PHP Printed Functions Here ## ## AND '$connect["datas"]' is NOT extracted ##; Expected result: ---------------- ## PHP Printed Functions Here ##; ## without "Warning: mysql_fetch_array ..." ##; ## AND '$connect["datas"]' is extracted ##; Actual result: -------------- ( Array ( [0] => 1 [logs] => Array ( [log] => Array ( [0] => Connection to DataBase Server = OK!; [1] => Connection to DB = (stibaiec_users) OK!; [2] => Running Command (SELECT * FROM `u_data_staffs` LIMIT 0 , 4;) = OK; [3] => Fetching Fields = OK -> total = (52); [4] => Extracting Data = OK -> total = (4); ) [ok] => Array ( [0] => Connection to DataBase Server = OK!; [1] => Connection to DB = (stibaiec_users) OK!; [2] => Running Command (SELECT * FROM `u_data_staffs` LIMIT 0 , 4;) = OK; [3] => Fetching Fields = OK -> total = (52); [4] => Extracting Data = OK -> total = (4); ) [error] => Array ( ) [warning] => Array ( ) ) [options] => (1)(1)(2)($) [affected_rows] => 4 [datas] => Array ( [0] => Array ( [uid] => abc [unim] => 0 [unip] => 0 [upass] => [ulevel] => 7 [usex] => 1 ) [1] => Array ( [uid] => def [unim] => 0 [unip] => 0 [upass] => [ulevel] => 6 [usex] => 1 ) [3] => Array ( [uid] => drakerafe [unim] => 0 [unip] => 0 [upass] => password [ulevel] => 7 [usex] => 1 ) ) [created by] => dRAke RafE ) )