!jazz Posted August 13, 2008 Share Posted August 13, 2008 Hi Guys, I'm currently developing a small Mysql wrapper and I'd like to ask you for a little help. How would you improve this method?: <?php public function sendQuery($Statement=NULL, $Variables=array()) { if($Statement!=NULL) { if($Variables!=NULL) { $Vars = NULL; if(is_array($Variables) && count($Variables)>0) { foreach($Variables as $key => $value) { $Vars .= ',\''.$this->escapeString($value).'\''; } } $Statement = '$query = sprintf("'.$Statement.'"'.$Vars.');'; eval($Statement); $query = mysql_query($query, $this->LinkID); if($query) { $this->Query = $query; } else { $this->errorSET('Query could not be executed', true); } } else { $query = mysql_query($Statement, $this->LinkID); if($query) { $this->Query = $query; } else { $this->errorSET('Query could not be executed', true); } } return $this->Query; } return false; } ?> So long, JaZz Link to comment https://forums.phpfreaks.com/topic/119457-mysql-wrapper-help/ Share on other sites More sharing options...
!jazz Posted August 13, 2008 Author Share Posted August 13, 2008 push Link to comment https://forums.phpfreaks.com/topic/119457-mysql-wrapper-help/#findComment-615415 Share on other sites More sharing options...
!jazz Posted August 13, 2008 Author Share Posted August 13, 2008 push Link to comment https://forums.phpfreaks.com/topic/119457-mysql-wrapper-help/#findComment-615673 Share on other sites More sharing options...
trq Posted August 13, 2008 Share Posted August 13, 2008 Theres probably a few things you could do but one thing that jumps out straight away is this loop. foreach($Variables as $key => $value) { $Vars .= ',\''.$this->escapeString($value).'\''; } It would be more efficient to replace it with a call to implode. $Vars = "'" . implode("','",$varaiables) . "'"; Link to comment https://forums.phpfreaks.com/topic/119457-mysql-wrapper-help/#findComment-615684 Share on other sites More sharing options...
!jazz Posted August 14, 2008 Author Share Posted August 14, 2008 Theres probably a few things you could do but one thing that jumps out straight away is this loop. foreach($Variables as $key => $value) { $Vars .= ',\''.$this->escapeString($value).'\''; } It would be more efficient to replace it with a call to implode. $Vars = "'" . implode("','",$varaiables) . "'"; Yeah thanks. Do you or someone else got some other suggestions? JaZz Link to comment https://forums.phpfreaks.com/topic/119457-mysql-wrapper-help/#findComment-616327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.