2016-11-19 8 views

답변

0
$this->CI->db->query("select * from $table $condition "); 

제거 CI 및

$this->db->query("select * from $table $condition "); 
1
<?php 

$this->db->select("your stuff"); 
$query = $this->db->get("your table"); 

if($query->num_rows() > 0) { 
    return 1; 
} 
else { 
    return 0; 
} 

?> 
0

먼저 데이터베이스

$autoload['libraries'] = array('database'); 

하는 경우를 자동로드가 당신이 다음 라이브러리를로드는 $ CI 인스턴스를 사용하려고 http://www.codeigniter.com/user_guide/general/ancillary_classes.html#get-instance

만약 모델

응용 프로그램> 라이브러리> Example.php

<?php 

class Example { 

    protected $CI; 

    public function __construct() { 
     $this->CI =& get_instance(); 
    } 

    public function somename() { 
     $query = $this->CI->db->query("select * from $table $condition "); 

     if ($query->num_rows() > 0) { 

     return 1; // return true; 

     } else { 

     return 0; // return false; 

     } 
    } 

} 

응용 프로그램> 모델> Example_model.php

<?php 

class Example_model extends CI_Model { 

    public function __construct() { 
    parent::__construct(); 
    } 

    public function somename() { 
     $query = $this->db->query("select * from $table $condition "); 

     if ($query->num_rows() > 0) { 

     return 1; // return true; 

     } else { 

     return 0; // return false; 

     } 
    } 

} 
+0

라이브러리 예에서 $ this-> CI에는 보호 된 $ CI가 있어야합니다. 또는 ... – TimBrownlaw

0

업데이트 한 CI 코어 파일을 작성하고 y를 해결하십시오. 우리의 오류 :

이동에 : DB_active_rec.php 파일 이동을 편집 시스템/데이터베이스/ 및 타격 코드

if ($query->num_rows() == 0) 
{ 
    return 0; 
} 

업데이트

if (!$query || $query->num_rows() == 0) 
{ 
    return 0; 
} 
에는 990 라인 않고 볼 수 있습니다

호프가 num_rows() 문제를 해결했습니다.