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@email.com";
$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@email.com', '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

Link to comment
Share on other sites

$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

Edited by OmeGa3
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.