public function exec($sql = "", $bindingValues = array(), $insert = true)
    {
        //Check if the query is a SELECT|INSERT|UPDATE and :variation is available
        if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) {
            
            $this->sql = $sql;

            //Always prepare the SQL statement first
            $query = $this->connection->prepare($sql);

            if (preg_match('/\s*:(.+?)\s/', $sql)) {
                if (is_array($bindingValues) && !empty($bindingValues)) {
                    foreach ($bindingValues as $key => $val) {
                        //Clean the bindingValues. Check if they start with :
                        if (!preg_match('/:.*/', $key)) {
                            $bindingValues[":" . $key] = $val;
                            unset($bindingValues[$key]);
                        }
                    }
                }


                //Add the binding variables to the query
                if ($query->execute($bindingValues)) {
                    return $this->getLastInsertID();
                } else {
                    //@ToDo:When the save or update fails make sure we handle the error gracefully!
                    throw new \Exception(implode("\n", $query->errorInfo()));
                }

            } else {
                $result = $query->execute();
            }

            if (preg_match('/.*(SELECT|SHOW).*/', $sql)) {
                $query->setFetchMode(\PDO::FETCH_ASSOC);
                return $query->fetchAll();
            }

            return $result;
        }


        return false;
    }
public function exec($sql = "", $bindingValues = array(), $insert = true)
    {
        //Check if the query is a SELECT|INSERT|UPDATE and :variation is available
        if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) {
            
            $this->sql = $sql;

            //Always prepare the SQL statement first
            $query = $this->connection->prepare($sql);

            if (preg_match('/\s*:(.+?)\s/', $sql)) {
                if (is_array($bindingValues) && !empty($bindingValues)) {
                    foreach ($bindingValues as $key => $val) {
                        //Clean the bindingValues. Check if they start with :
                        if (!preg_match('/:.*/', $key)) {
                            $bindingValues[":" . $key] = $val;
                            unset($bindingValues[$key]);
                        }
                    }
                }


                //Add the binding variables to the query
                if ($query->execute($bindingValues)) {
                    return $this->getLastInsertID();
                } else {
                    //@ToDo:When the save or update fails make sure we handle the error gracefully!
                    throw new \Exception(implode("\n", $query->errorInfo()));
                }

            } else {
                $result = $query->execute();
            }

            if (preg_match('/.*(SELECT|SHOW).*/', $sql)) {
                $query->setFetchMode(\PDO::FETCH_ASSOC);
                return $query->fetchAll();
            }

            return $result;
        }


        return false;
    }
public function exec ( $ sql = "" , $ bindingValues = array ( ) , $ insert = true ) { //Check if the query is a SELECT|INSERT|UPDATE and :variation is available if ( preg_match ( "/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/" , $ sql ) ) { $ this -> sql = $ sql ; //Always prepare the SQL statement first $ query = $ this -> connection -> prepare ( $ sql ) ; if ( preg_match ( '/\s*:(.+?)\s/' , $ sql ) ) { if ( is_array ( $ bindingValues ) && ! empty ( $ bindingValues ) ) { foreach ( $ bindingValues as $ key => $ val ) { //Clean the bindingValues. Check if they start with : if ( ! preg_match ( '/:.*/' , $ key ) ) { $ bindingValues [ ":" . $ key ] = $ val ; unset ( $ bindingValues [ $ key ] ) ; } } } //Add the binding variables to the query if ( $ query -> execute ( $ bindingValues ) ) { return $ this -> getLastInsertID ( ) ; } else { //@ToDo:When the save or update fails make sure we handle the error gracefully! throw new \ Exception ( implode ( "\n" , $ query -> errorInfo ( ) ) ) ; } } else { $ result = $ query -> execute ( ) ; } if ( preg_match ( '/.*(SELECT|SHOW).*/' , $ sql ) ) { $ query -> setFetchMode ( \ PDO :: FETCH_ASSOC ) ; return $ query -> fetchAll ( ) ; } return $ result ; } return false ; }
Executes the current SQL query.
Returns a ASSOC result set.

@param string $sql
@param array $bindingValues
@param bool $insert
@return mixed
Executes the current SQL query . Returns a ASSOC result set .