Jump to content

Warning: mysql_fetch_array(): The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH


OmeGa3

Recommended Posts

Hello the community,

 

i have create a little script that connect to the mysql database & search for the email field

 

<?
$host = "localhost";
$user = "root";
$password = "password";
$db = "test";
$type = "MYSQL_BOTH";
$conn = mysql_connect($host, $user, $password);
mysql_select_db($db) or die("cannot open DB $db");
$file = "http://localhost/tmp/log.txt";
$result = parse_table ( "user",$type,"file" );
mysql_close($conn);

function parse_table($tablename,$mode,$file) {
$email= "[email protected]";
$fo = fopen($file,"w++");
$sql = "SELECT email FROM user WHERE email = '".$email."'";

$req = mysql_query($sql)or die('Error SQL !<br>'.$sql.'<br>'.mysql_error());
$tbl_array = array();
while($data = mysql_fetch_array($req, $mode)) {
foreach($data as $key => $value) {
$tbl_array[$key][] = $value;
fputs ($fo,$tbl_array[$key]);
 }
}
}

?>

 

 

here is the sql dump

 

/*
CREATE TABLE IF NOT EXISTS user ( id int(10) unsigned NOT NULL AUTO_INCREMENT,
email varchar(80) NOT NULL,
pass char(41) NOT NULL, PRIMARY KEY (id) )
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; INSERT INTO user
(id, email, pass) VALUES (1, '[email protected]', '664c0750f8c73ec0086e88c8b02bb112'');
*/

 

 

the problem is i got an error

 

Warning: mysql_fetch_array(): The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH. in C:\server\www\test.php on line 20

 

the line 20 is

while($data = mysql_fetch_array($req, $mode)) {

 

im not sure where the problem come from

 

could you help me to fix the script please ?

 

thx you very much

$type = "MYSQL_BOTH";

The type has to be the actual constant MYSQL_BOTH, not a string containing its name.

 

thx you requinix ,

i have made the change as you sugest

$type = MYSQL_BOTH;

 

it look like it work but i obtain this

 

Notice: Array to string conversion in C:\server\www\test.php on line 23 Notice: Array to string conversion in C:\server\www\test.php on line 23

 

wich is

fputs ($fo,$tbl_array[$key]);

 

into the file.txt created i got this result

ArrayArray

 

meaning there is something missing in my code

The line above that should be

$tbl_array[$key] = $value;

but that's not the problem.

 

As the error message says, you have an array ($tbl_array[$key]) but fputs() wants a string. So how do you want to handle that conversion?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.