-3

I have the following code

 mysql_select_db('example_db', $r);
 $result1 = mysql_query('SELECT content FROM `example_table` WHERE 1') or die ('"bad times an error!"' . mysql_error() . '');
 echo $result1;

which returns "Resource ID #114". What does this mean? The info I'm trying to pull is a base64 & json encoded twitter feed stored in a DB. I've tried adding the base64 & json decoding, but get an error stating that it's a resource and not a string, so I assume it's trying to parse "Resource ID #114" rather than the actual feed itself.

Any help is appreciated!

SoWizardly
  • 387
  • 1
  • 6
  • 16

2 Answers2

0

Have another look at the documentation: mysql_query will return an resource object. You have to work with it to extract the data. mysql_fetch_array or mysql_fetch_assoc will help you.

WATCH OUT:

You should not use the mysql_* - functions anymore. They are deprecated and will be not longer supported by >= php 5.5 . You should switch to mysqli_* or PDO

Tobias Golbs
  • 4,586
  • 3
  • 28
  • 49
0

Resources are custom variables in php like (but different) Streams. You may read the documentation first:

A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions. See the appendix for a listing of all these functions and the corresponding resource types.

Second problem is you're using mysql_query() like deprecated and ancient methods. This is very bad. You should use other (more modern) interfaces (like PDO or mysqli) when interacting with db.

In your example, $result1 is a resource, you can't print it like that. You have to iterate on it:

while ($row = mysql_fetch_assoc($result1)) {
    echo $row['columnName'];
}
edigu
  • 9,878
  • 5
  • 57
  • 80