2016-11-19 11 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

まず、あなたが$ CIインスタンスを使用して、ライブラリをロードしようとしている場合は、データベース

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

をAUTOLOAD持って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

更新1つのCIコアファイルを作成して解決する私たちのエラー:

移動先:システム/データベース/DB_active_rec.phpファイル ゴーを編集なし990行目ないし、参照するには、ブローコード

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

更新

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

あなたのnum_rows()問題を解決しました。

関連する問題