clem_c_rock Posted June 19, 2009 Share Posted June 19, 2009 Hello, I just ported a site over to a new server w/ a newer version of php. I am having a strange problem using the extract() function to extract contents of a mysql_fetch_array. I know it's the extract function because when I comment it out the page loads with no problem. here's my code: $sql_select = "select property.*, layout.* from property,layout where property.property_id=$property_id and layout.property_id=$property_id"; $result = mysql_query ($sql_select, $conID); $row = array(); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ extract($row); } Any ideas on why this is happening? thanks for your time! Link to comment https://forums.phpfreaks.com/topic/162932-problems-with-extract-function-causing-page-timeout/ Share on other sites More sharing options...
DavidAM Posted June 19, 2009 Share Posted June 19, 2009 Because both tables have a column named property_id, you are getting column names of property.property_id and layout.property.id so they can be distinguished in the query result. These column names are not valid variable names so extract will not create variables for them. On the PHP manual page for extract(), in the user comments (http://us3.php.net/manual/en/function.extract.php): They say "If the result is not a valid variable name, it is not imported into the symbol table." What they should say is that if _any_ of the results have invalid names, _none_ of the variables get extracted. I quit using extract() early on just to make my code clearer, so I don't know if this "feature" exists in newer versions of PHP or older versions or all. To avoid this, you will have to explicitly name the columns you want in the SELECT, make sure all the column names are valid names for PHP variables, make sure there are no duplicate column names, use columnName AS newName to force a different name for a column. Link to comment https://forums.phpfreaks.com/topic/162932-problems-with-extract-function-causing-page-timeout/#findComment-859723 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2009 Share Posted June 19, 2009 extract is probably overwriting something. A) You should only use extract with the EXTR_PREFIX_ALL parameter and a unique prefix so that there is absolutely no chance at all of overwriting any existing variable, and B) To help debug what it is actually doing, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/162932-problems-with-extract-function-causing-page-timeout/#findComment-859745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.