physaux Posted April 9, 2010 Share Posted April 9, 2010 Ok so, can I run an SQL query inside of a function? For example, look at my code below. Can I do that? function dosomething(){ $sqlquery = "SELECT * FROM $table WHERE ip_address = '$ip' LIMIT 1;"; $results = mysql_query($sqlquery); $rowoutput = mysql_fetch_assoc($results); $chosenurl = $rowoutput['url']; return $chosenurl; } mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); //... $url = dosomething(); //... I know that for variables, I have to say 'global'. Do I need to do something like that for this mysql query as well? Link to comment https://forums.phpfreaks.com/topic/198066-can-i-run-a-mysql-query-from-inside-a-function-when-mysql_connect-was-outside/ Share on other sites More sharing options...
JAY6390 Posted April 9, 2010 Share Posted April 9, 2010 Yes you can Link to comment https://forums.phpfreaks.com/topic/198066-can-i-run-a-mysql-query-from-inside-a-function-when-mysql_connect-was-outside/#findComment-1039253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.