|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Variables
Hi
I was wondering if this is the correct way to reference a variable from a file that has been included inside of a function. Also just general static/global variable usage. For example: Myqsql_functions.php <?php require("config.php") function ach_mysqlCon() { static $con = mysql_connect(global $mysql_host,$mysql_user,$mysql_pass); if (!$con) { die('Could not connect: ' . mysql_error()); } } function ach_mysqlCloseCon() { if($con) { mysql_close($con) } } ?> And the variables are defined in config.php config.php <?php //Mysql vars $mysql_host = "localhost"; $mysql_user = "user@localhost"; $mysql_pass = ""; ?> So my questions are will ach_mysqlCloseCon() recognise the $con variable in ach_mysqlCon() as it is declared as static? will ach_mysqlCon() recognise the variables included from config.php as they are declared global? is this all syntax'd properly? Also, how would I, for example, change $mysql_host from a form? Cheers and thanks for any and all assistance. |
![]() |
| Viewing: Web Development Archives > Mailing Lists > PHP > Variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|