Cod-nes Posted July 23, 2009 Share Posted July 23, 2009 Do we have to recall the mysql when making a function?Example: <?phpmysql_connect("server","user","password") or die();mysql_select_db("database") or die();function countrows() {// Do we need to reconnect so that this function can work? //mysql_connect("server","user","password") or die();//mysql_select_db("database") or die();$sql = mysql_query("SELECT *");$sql = mysql_count_rows($sql);//mysql_close();return $sql;}mysql_close();?> Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 23, 2009 Share Posted July 23, 2009 No, if you have already connected somewhere globally (like you did above). Link to comment Share on other sites More sharing options...
Cod-nes Posted July 23, 2009 Author Share Posted July 23, 2009 No, if you have already connected somewhere globally (like you did above).Is this for php 4 and 5? or just 5? Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 23, 2009 Share Posted July 23, 2009 I'm not sure, my guess is that it applies to all versions of PHP that supported mysql_connect or mysqli_connect. Link to comment Share on other sites More sharing options...
Synook Posted July 23, 2009 Share Posted July 23, 2009 All php_mysql versions look for the connection handler in the global namespace. So you don't need to re-connect. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.