2011-11-01 8 views
1

내 사용자 정의 함수를 사용하여 MySQLi 쿼리를 실행할 때이 오류가 발생합니다 ...MySQLi 쿼리가 제대로 작동하지 않습니다.

Fatal error: Call to a member function execute() on a non-object in /Applications/MAMP/htdocs/RevFramework/Application/Model/Engine/eMySQLi.php on line 92 

실제로 무엇이 잘못되었는지를 모르는 경우 ... 즉 $ types 및 $ params를 null로 설정하면 그렇지 않습니다. 나는 call_user_func_array도 오류를 던질 것이라고 확신합니다.

public function query($SQL, $types = null, $params = null) 
   { 
           $this->result = $this->db->prepare($SQL); 
        
           if(isset($types) && isset($params)) 
           { 
               $bind_names[] = $types; 
                
               for ($i = 0; $i < count($params); $i++) 
               { 
                   $bind_name = 'bind' . $i; 
                   $$bind_name = $params[$i]; 
                   $bind_names[] = &$$bind_name; 
               } 
            
               call_user_func_array(array($this->result, 'bind_param'), $bind_names); 
           } 

           $this->result->execute(); 
   } 

수행중인 쿼리 :

$class->query("SELECT name FROM rev_widgets ORDER BY order"); 

무엇이 잘못 될 수 있는지 전혀 알지 못합니다.

어떤 도움을 주셔서 감사합니다!

+2

'$ this-> result = $ this-> db-> prepare ($ SQL);'라는 줄은 예상 한 것을 반환하지 않습니다. 'vardump ($ this-> result)'의 출력을 게시 할 수 있습니까? 또한, throw되는 오류 및 예외에 대한 자세한 내용은 [PDO :: prepare 설명서] (http://php.net/manual/en/pdo.prepare.php)를 참조하십시오. –

+0

'var_dump ($ this-> result);'는'bool (false)'를 반환합니다. 감사합니다.하지만 MySQLi를 사용하고 있습니다. –

+1

bool (false)는'result' 필드에 어떤 객체도 포함되어 있지 않다는 것을 의미합니다. 아마도'db-> prepare()'메소드가 실패했을 것이다. – ariefbayu

답변

0

답변을 찾았습니다! 글쎄, 그냥 전방으로 가서 아주 다르게했다.

필요한 모든 사람들에게 이제는이 모든 것이 보입니다.

class Core_Model extends Core_Controller 
{ 

     private $connected; 

     private $db; 

     protected $result; 

    public function __construct() 
    { 
      //$this->connect(); 
    } 

     protected function connect() 
     { 
      if($this->connected != true) 
      { 
       $this->db = new mysqli($this->data['host'], $this->data['user'], $this->data['pass'], $this->data['database']); 

       if($this->mysqli->connect_errno)  
       { 
        $this->error($mysqli->connect_errno); 
       } 

       $this->connected = true; 
      } 
     } 

     protected function disconnect() 
     { 
      if($this->connected == true) 
      { 
       $this->db->close(); 
       $this->connected = false; 
      } 
     } 

     public function newQuery() 
     { 
      $this->connect(); 

      if(is_object($this->result)) 
      { 
       $this->result->close(); 
      } 

      return $this; 
     } 

     public function query($SQL, $params = null) 
     { 
      $this->newQuery(); 

      if(($this->result = $this->db->prepare($SQL))) 
      { 
       if($params != null) 
       { 
        call_user_func_array(array($this->result, 'bind_param'), $this->refreshParams($params)); 
       } 

       $this->result->execute(); 
      } 
      else 
      { 
       trigger_error("MySQLi query <i> '" . $SQL . "'</i> failed", E_USER_ERROR); 
      } 

      return $this; 
     } 

     public function get() 
     { 
      $parameters = $this->getFieldNames(); 
      call_user_func_array(array($this->result, 'bind_result'), $this->refreshParams($parameters)); 

      while($this->result->fetch()) 
      { 
       $x = array(); 

       foreach($this->row as $key => $val) 
       { 
        $x[$key] = $val; 
       } 

       $data[] = $x; 
      } 

      return $data; 
     } 

     public function id() 
     { 
      return $this->mysql->insert_id; 
     } 

     public function num_rows() 
     { 
      $this->result->store_result(); 

      return $this->result->num_rows; 
     } 


    private function getFieldNames() 
    { 
      $meta = $this->result->result_metadata(); 

      while($field = $meta->fetch_field()) 
      { 

       $parameters[] = &$this->row[$field->name]; 

      } 

      return $parameters; 
     } 

     private function refreshParams($params) 
     { 
      $temp = array(); 

      foreach($params as $key => $value) 
      { 
       $temp[$key] = &$params[$key]; 
      } 

      return $temp; 
     } 
} 

희망이 있으면 도움이 될 것입니다.

관련 문제