Jump to content

mysql_query resource id into array


TecnobA

Recommended Posts

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());
Link to comment
Share on other sites

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, [url=http://us3.php.net/manual/en/ref.mysqli.php]http://us3.php.net/manual/en/ref.mysqli.php[/url].  Try this out:

[code]
<?php
.....

$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.
.....
?>
[/code]

I think that's what you're looking for.  If I just went out on a tangent for no reason, then I apologize.
Link to comment
Share on other sites

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