Jump to content

Simpler method of getting variables from mysql


Merdok

Recommended Posts

Hi Guys,

 

I'm trying to streamline my CMS's code and as I was writing a new page it occured to me that there might be an easier way to get variables from a mysql query and that if anyone knew how to do it, it would be you guys.

 

Here is the code I use now:

 

	// Pulls the data from the database
$dblookup = "SELECT moduleID, menu_name, stylesheet_name, display_name, has_menu, access_control, installed, compatible, active FROM core_modules WHERE moduleID=" . $_GET['ID'];
$data = mysql_query($dblookup) or die('Failed to return data: ' . mysql_error());
/* sorts the data into variables and puts them in an array ready to be called when needed */
list($moduleID, $menu_name, $stylesheet_name, $display_name, $has_menu, $access_control, $installed, $compatible, $active) = mysql_fetch_array($data, MYSQL_NUM);
}

 

Is there a way I can just do SELECT * FROM and then have it automatically extract the data into variables based on the column name?

 

 

You should use the EXTR_PREFIX_ALL 2nd parameter and specify a unique prefix as the 3rd parameter to insure you don't overwrite any existing program variables (someone recently had that happen here in the Forum.)

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.