Page 1 of 1

Convert to String

Posted: Sun Mar 27, 2011 12:47 pm
by afr_dnf2011
Is there any way to convert Resource id # to a string ?

Re: Convert to String

Posted: Sun Mar 27, 2011 4:50 pm
by social_experiment
Resource id # can be a result received from a mysql query. You have to pass the resource id to something like mysql_fetch_array().

Code: Select all

<?php
 $query = mysql_query("SELECT * FROM table");
 echo $query; 
 // echoes 'Resource id #
?>

Re: Convert to String

Posted: Sun Mar 27, 2011 7:57 pm
by afr_dnf2011
social_experiment wrote:Resource id # can be a result received from a mysql query. You have to pass the resource id to something like mysql_fetch_array().
Dear social experiment, thanks for your valuable reply. Yes, you are correct. now, Let's check the code below.

Code: Select all

$file = fopen("myfile.txt", "w");
var_dump($file);
Isn't the variable $file is resource id # type?

Re: Convert to String

Posted: Sun Mar 27, 2011 8:09 pm
by afr_dnf2011
Just look at the twist below.

Code: Select all

$file = fopen("myfile.txt", "w");
var_dump($file); //resource(3) of type (stream) (output)
echo "<br>";
fclose($file);
var_dump($file); // resource(3) of type (Unknown) (output)
Why?

Re: Convert to String

Posted: Mon Mar 28, 2011 10:08 am
by social_experiment
With twist, are you refering to the second result when the value of $file is dumped? You are closing the file pointer in the previous line so it makes sense that you would get the result you are getting.