Jump to content

Mysql Wrapper - Help


!jazz

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.