small function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

small function

Post by rsmarsha »

I wrote a small function for queries:

Code: Select all

function db_query($sql, $name)
{
	$string = $sql;
	global $query;
	$query = mysql_query($string) or die("Query($name): $string Failed".mysql_error());
}
How would i change that so that the last line would change depending on what $name was?

So if name was test it would be

Code: Select all

$test = mysql_query($string) or die("Query($name): $string Failed".mysql_error());
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Don't use global variables like that. It's asking for trouble.
Post Reply