php_fish Posted May 17, 2010 Share Posted May 17, 2010 I'm storing mysql queries in a database. I want to store the $_GET key in my query so that when I pull the query from the db it replaces '$_GET['id']' with whatever the value happens to be, eg $sql = "SELECT * FROM users WHERE user_id = ".$_GET['id'] I serialize the data before it's entered into the db as the qury is part of an array of data. I just can't work out the proper format. It's fine when I don't have a dynamic variable inside the query. Any help will be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/202014-serialize-global-keys-_get-var/ Share on other sites More sharing options...
Adam Posted May 17, 2010 Share Posted May 17, 2010 How are you executing the query? Quote Link to comment https://forums.phpfreaks.com/topic/202014-serialize-global-keys-_get-var/#findComment-1059409 Share on other sites More sharing options...
php_fish Posted May 17, 2010 Author Share Posted May 17, 2010 I pull the stored query from the database then use it. At he moment I'm doing a preg_replace on the query but wondered if there is a better way to do it Quote Link to comment https://forums.phpfreaks.com/topic/202014-serialize-global-keys-_get-var/#findComment-1059449 Share on other sites More sharing options...
Adam Posted May 17, 2010 Share Posted May 17, 2010 Yeah that's normal behaviour, PHP only sees the query as a string of text and so doesn't parse the variable. When you actually execute the query do you know which you're parsing or are they run in some form of loop? I'm thinking you could replace variables with '%s' and use sprintf to add the dynamic values..? Quote Link to comment https://forums.phpfreaks.com/topic/202014-serialize-global-keys-_get-var/#findComment-1059456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.