OmeGa3 Posted January 10, 2013 Share Posted January 10, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/272917-warning-mysql_fetch_array-the-result-type-should-be-either-mysql_num-mysql_assoc-or-mysql_both/ Share on other sites More sharing options...
requinix Posted January 10, 2013 Share Posted January 10, 2013 $type = "MYSQL_BOTH"; The type has to be the actual constant MYSQL_BOTH, not a string containing its name. Quote Link to comment https://forums.phpfreaks.com/topic/272917-warning-mysql_fetch_array-the-result-type-should-be-either-mysql_num-mysql_assoc-or-mysql_both/#findComment-1404540 Share on other sites More sharing options...
OmeGa3 Posted January 10, 2013 Author Share Posted January 10, 2013 (edited) $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 January 10, 2013 by OmeGa3 Quote Link to comment https://forums.phpfreaks.com/topic/272917-warning-mysql_fetch_array-the-result-type-should-be-either-mysql_num-mysql_assoc-or-mysql_both/#findComment-1404545 Share on other sites More sharing options...
requinix Posted January 10, 2013 Share Posted January 10, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/272917-warning-mysql_fetch_array-the-result-type-should-be-either-mysql_num-mysql_assoc-or-mysql_both/#findComment-1404556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.