0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

This is my code where I am connecting the database through object and class.

$this->db_connection($app_config['database']);
$this->table_name = $app_config['database']['tbl_prefix'].strtolower(get_class($this));
$column_q = $this->query("SHOW COLUMNS FROM {$this->table_name}");
while($rows = mysql_fetch_array($column_q)){    #error showing in this line
  $column[] = $rows['Field'];
  if($rows['Field'] == 'PRI'){
    $this->primary_key = $rows['Field'];
  }
}

It is showing some error like

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

can some one tell me what is the error and how to fix this?

Community
  • 1
  • 1
NewUser
  • 12,175
  • 36
  • 139
  • 230
  • one live above the error, your query fails and returns FALSE. so the var hold FALSE and this is what you give to mysql_fetch_array – Rufinus Jun 07 '11 at 12:31

2 Answers2

0

My guess is your query is failing and the following is returning false:

$column_q = $this->query("SHOW COLUMNS FROM {$this->table_name}");

Do a var_dump($column_q) or echo your query to ensure it is as expected.

Jason McCreary
  • 69,176
  • 21
  • 125
  • 169
0

Maybe this->query returns false on query with error? So your will need:

if ( $column_q = $this->query("SHOW COLUMNS FROM {$this->table_name}")) 
  while($rows = mysql_fetch_array($column_q)){...}    #error showing in this line
else
   echo "Error!"

PS. I prefer simply return return $mdb->query() in own simple mysql class ... or show error.

publikz.com
  • 918
  • 1
  • 12
  • 21