Jump to content

Can I run a MYSQL query from inside a function when MYSQL_CONNECT was outside?


physaux

Recommended Posts

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.