Jump to content


mysql_query resource id into array

  • Please log in to reply
2 replies to this topic

#1 TecnobA

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 August 2006 - 12:30 AM

When  i want to store a mysql_query resource id into array i get this error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/localhost/htdocs/projekti/blog/libaries/Mysql.class.php on line 61

line 61: $this->query[$field] = mysql_query($query, $this->link) or die( "<b>MySQL error:</b> ".mysql_error());

But if i don't store a resource id into array, everything is ok. Why?

No error: $this->query = mysql_query($query, $this->link) or die( "<b>MySQL error:</b> ".mysql_error());

#2 mewhocorrupts

  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationParker, CO

Posted 12 August 2006 - 05:33 AM

I think what you're trying to do is instantiate an object that isn't actually created when you call the connect function.  What you're looking for is MySQLI, http://us3.php.net/m.../ref.mysqli.php.  Try this out:


$db = new mysqli("SERVER","DB","PASS","TABLE");
$res = $db->query($sql_query_string);
$row = mysqli_fetch_array($res, MYSQLI_ASSOC);

$col1 = $row['col1'];
$col2 = $row['col2'];

// And so on and so forth.  You can also MYSQLI_NUM if you want to reference like
//  $row[1] and $row[2].  MYSQLI_BOTH will give you access to both number
//  and literal string column references.

I think that's what you're looking for.  If I just went out on a tangent for no reason, then I apologize.

#3 crazy manzaaa

crazy manzaaa
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 August 2006 - 06:48 AM

here's my take:
by using $this->query[$field], you already specify the array's 'key' (=$field).  However, the mysql_query(...) returns a result (which is also an array) that has its own 'key' .  So, you don't need to specify the key.

I don't know if this will work or not.  Try to use $this->query[] instead.  If that doesn't work, nevermind.  You already get an array anyway.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users