Spikerok Posted February 28, 2010 Share Posted February 28, 2010 I have array which contains next entry 'rowcount' => array( 0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id = \'\" . $this->feld[\'txtDomain\'] . \"\'|Domain already exists' Given array is processed using next code. I'm calling this process after declaring array and filling it with values. $felder = explode('|', $this->array['rowcount'][0]); $sql = stripslashes($felder[0]); $result = $this->registry['conn']->query($sql); $numrows = $result->rowCount(); $this->feld[txtDomain] = 123 $sql = stripslashes($felder[0]); will show SELECT domain_id FROM `tbl_domain` WHERE `domain_id` = '" . $this->feld['txtDomain'] . "' when it should of changed '" . $this->feld['txtDomain'] . "' to 123 What could be done? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted February 28, 2010 Share Posted February 28, 2010 Can you show the code that created the array with your query string in it? Quote Link to comment Share on other sites More sharing options...
Spikerok Posted February 28, 2010 Author Share Posted February 28, 2010 I have first page which calls object and contains array. $array = array('rowcount' => array( 0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id = \'\" . $this->feld[\'txtDomain\'] . \"\'|Domain already exists', 1 => 'SELECT user_id FROM buga WHERE user_id = \'\" . $this->feld[\'txtID\'] . \"\'|User does not exist')); new process($this->registry, $array); then in class process i have function rowcount private function rowcount() { $max = count($this->array['rowcount']); for($i = 0; $i < $max; $i++) { $felder = explode('|', $this->array['rowcount'][$i]); $sql = stripslashes($felder[0]); $result = $this->registry['conn']->query($sql); $numrows = $result->rowCount(); if($numrows < 1){ $_SESSION['errorMessage']= $felder[1]; } } } array '$this->feld' is declared in class with values. Quote Link to comment Share on other sites More sharing options...
Spikerok Posted February 28, 2010 Author Share Posted February 28, 2010 because array is created before starting class and class contains variable which is used in array, array thinks that the sql string with variable ( which are undefined ) in it is just a string. Well every thing that contained in array is a string, so i have changed array slightly. $array = array('rowcount' => array( 0 => 'SELECT domain_id FROM tbl_domain WHERE domain_id =|txtDomain|Domain already exists'); new process($this->registry, $array); and in function. $felder = explode('|', $this->array['rowcount'][$i]); $sql = $felder[0]; $sql .= "'" . $this->feld[$felder[1]] . "'"; Quote Link to comment Share on other sites More sharing options...
Andy-H Posted February 28, 2010 Share Posted February 28, 2010 you just need to double quote your query string when creating your array so that the variable will be replaced within the string at runtime. //EDIT Ahh got you, the variable being used is a class member lol Quote Link to comment Share on other sites More sharing options...
Spikerok Posted February 28, 2010 Author Share Posted February 28, 2010 yep Quote Link to comment 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.