How to find whether a variable is a resource in PHP

2 Answers

0 votes
$con = @mysql_connect('localhost', 'root_user');
if (is_resource($con)) 
    echo '$con is a resource';
else
    die('connection error : ' . mysql_error());



/*
run: 

$con is a resource 

*/

 



answered Jul 1, 2016 by avibootz
0 votes
$fp = fopen('d:\\data.txt','r');  
if (is_resource($fp)) 
    echo '$fp is a resource';
else
    die('error open file');



/*
run: 

$fp is a resource 

*/

 



answered Jul 1, 2016 by avibootz

Related questions

3 answers 207 views
8 answers 432 views
4 answers 227 views
2 answers 207 views
1 answer 217 views
2 answers 267 views
...