Asked  7 Months ago    Answers:  5   Viewed   43 times

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

I'm very confused with this error, it shows when I try to return a result from the DB that doesn't exist ... I tried mysql_num_rows() but it returns the same error but instead of mysql_fetch_assoc expects ... it says mysql_num_rows() expects ...

I set error_reporting(0) to avoid showing this error, but I'm not satisfied with this solution ...

 Answers

61

Here's the proper way to do things:

<?PHP
$sql = 'some query...';
$result = mysql_query($q);

if (! $result){
   throw new My_Db_Exception('Database error: ' . mysql_error());
}

while($row = mysql_fetch_assoc($result)){
  //handle rows.
}

Note the check on (! $result) -- if your $result is a boolean, it's certainly false, and it means there was a database error, meaning your query was probably bad.

Wednesday, March 31, 2021
 
JackTheKnife
answered 7 Months ago
67

mysql_real_escape_string just takes a string for an argument. That's it.

$string = mysql_real_escape_string('string')

If you want to specify the link identifier, it is the optional second argument:

$string = mysql_real_escape_string('string', $dbc)

Wednesday, March 31, 2021
 
nighter
answered 7 Months ago
28

Sometimes that warning is that if the result of the query within while returns no value, that is, such as when no records on table.

What I mean is that in some cases your code and your application is correct and yet the warning appears.

to hide the warning uses the character @.

e.g.

while(@$rs = mysql_fetch_array($sql)) {
   ...
}

Best regards

Wednesday, March 31, 2021
 
Norgul
answered 7 Months ago
56

Probably mysql_query() failed. In this case it returns false. Use mysql_error() to find out, what happens.

Wednesday, June 2, 2021
 
Besnik
answered 5 Months ago
39

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/config.inc.php

Tuesday, July 13, 2021
 
ShadowZzz
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share