Re: Evaluate PHP var in stored sql statement?

From: Date: Fri, 24 Jan 2003 19:02:10 +0000
Subject: Re: Evaluate PHP var in stored sql statement?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-133025@lists.php.net to get a copy of this message
eval takes the string and executes PHP in that string. So, eval("\$myrow[2] = \"$myrow[2]\";"); is equivalent to: $myrow[2] = "$myrow[2]"; I'd reccomend you using single quotes and then escape only backslashes and single quotes within a string -- Maxim Maletsky maxim@php.net "Noah" <noah@newminddesign.com> wrote... : > Don't quite understand why this works, but it does: > > /* Escape quotes in sql_query so our header_id gets evaluated */ > eval("\$myrow[2] = \"$myrow[2]\";"); > > What's the deal with the leading backslash in ' eval("\$myrow[2] '? > > Does eval() tell php to evaluate the string as php code; i.e. text without > quotes? > > Thanks for the help....... > > --Noah > > > ----- Original Message ----- > From: "Maxim Maletsky" <maxim@php.net> > To: "CF High" <noah@newminddesign.com> > Cc: <php-general@lists.php.net> > Sent: Friday, January 24, 2003 9:59 AM > Subject: Re: [PHP] Evaluate PHP var in stored sql statement? > > > > > > use eval() > > > > www.php.net/eval > > > > > > -- > > Maxim Maletsky > > maxim@php.net > > > > > > > > "CF High" <noah@newminddesign.com> wrote... : > > > > > Hey all. > > > > > > I need to find out how to get PHP to evaluate a PHP variable stored in > our > > > MySql database. > > > > > > Currently the variable is being read as a string; i.e. select * from > table > > > where column = $myrow[0] -- instead of evaluating $myrow[0] as a > variable. > > > > > > > > > The SQL statement is retrieved in the first call to dbConnect (see code > > > below) > > > > > > > > > > > > dbConnect("SELECT header_id, header, sql_query FROM cat_headers WHERE > > > section_id = $_REQUEST[section_id] order by header"); > > > > > > $set = $result; /* Give initial result set a unique name */ > > > > > > while ($myrow = mysql_fetch_row($set)) { > > > > > > echo(Display the header title here); > > > > > > > > > dbConnect($myrow[2]); /* $myrow[2] is the sql_query > gotten > > > from the first dbConnect() call */ > > > > > > $set1 = $result; /* Give next result set a unique name > */ > > > > > > while ($myrow = mysql_fetch_row($set1)) { > > > > > > echo(Display category rows here); > > > > > > } > > > > > > } > > > > > > -- > > > Any leads/suggestions much appreciated.......... > > > > > > --Noah > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#133025) next »