From: deviant_two at yahoo dot com
Operating system: winxpsp2
PHP version: 5.2.9
PHP Bug Type: Unknown/Other Function
Bug description: function_exists + mysql_fetch_array
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 = ";
$li...@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:
'x...@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
)
)
--
Edit bug report at http://bugs.php.net/?id=48457&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48457&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48457&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48457&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48457&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48457&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48457&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48457&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48457&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48457&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48457&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48457&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48457&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48457&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48457&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48457&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48457&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48457&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48457&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48457&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48457&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48457&r=mysqlcfg