Convert to String
Moderator: General Moderators
- afr_dnf2011
- Forum Newbie
- Posts: 14
- Joined: Mon Mar 21, 2011 8:20 pm
Convert to String
Is there any way to convert Resource id # to a string ?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Convert to String
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 #
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- afr_dnf2011
- Forum Newbie
- Posts: 14
- Joined: Mon Mar 21, 2011 8:20 pm
Re: Convert to String
Dear social experiment, thanks for your valuable reply. Yes, you are correct. now, Let's check the code below.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().
Code: Select all
$file = fopen("myfile.txt", "w");
var_dump($file);
- afr_dnf2011
- Forum Newbie
- Posts: 14
- Joined: Mon Mar 21, 2011 8:20 pm
Re: Convert to String
Just look at the twist below.
Why?
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)
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Convert to String
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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering