Jump to content

Archived

This topic is now archived and is closed to further replies.

TecnobA

mysql_query resource id into array

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());

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.