Cod-nes Posted July 23, 2009 Report Share Posted July 23, 2009 (edited) 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();?> Edited July 23, 2009 by Cod-nes Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 23, 2009 Report 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 Report 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 Report 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 Report 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
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now