• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to undefined function CAST()

#1
Hi! Im having an error in using the cast function in my model. Does cast() works in codeigniter?

Here is my code.

   public function gen_report($personnel, $ym)
   {
       //print_r($personnel);exit();
       if($personnel != null){
           $query = $this->db->select('*')
               ->join('document_activity b', 'b.document_id = a.id')
               ->join('personnel c', 'c.id = b.receiver_personnel_id')
               ->join('document_type d', 'd.doctype_id = a.document_type_id')
                ->like('a.date_received', $ym)
                    ->CAST('a.tracking_no AS UNSIGNED')
                    ->order_by('date_received', 'ASC')
               ->where('b.receiver_personnel_id',$personnel)
               ->get('document a');
        }else{
            $query = $this->db->select('*')
            ->join('document_activity b', 'b.document_id = a.id')
            ->join('personnel c', 'c.id = b.receiver_personnel_id')
            ->join('document_type d', 'd.doctype_id = a.document_type_id')
            ->like('a.date_received', $ym)
                ->CAST('a.tracking_no AS UNSIGNED')
                ->order_by('date_received', 'ASC')
            ->get('document a');
        }
       
       if($query->num_rows() > 0){
           return $query->result();
       }else{
           return false;
       }
   }
Reply

#2
Please provide code example of what you're trying so that we can help.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#3
    Here is my code 

public function gen_report($personnel, $ym)
   {
       //print_r($personnel);exit();
       if($personnel != null){
           $query = $this->db->select('*')
               ->join('document_activity b', 'b.document_id = a.id')
               ->join('personnel c', 'c.id = b.receiver_personnel_id')
               ->join('document_type d', 'd.doctype_id = a.document_type_id')
                ->like('a.date_received', $ym)
                    ->CAST('a.tracking_no AS UNSIGNED')
                    ->order_by('date_received', 'ASC')
               ->where('b.receiver_personnel_id',$personnel)
               ->get('document a');
        }else{
            $query = $this->db->select('*')
            ->join('document_activity b', 'b.document_id = a.id')
            ->join('personnel c', 'c.id = b.receiver_personnel_id')
            ->join('document_type d', 'd.doctype_id = a.document_type_id')
            ->like('a.date_received', $ym)
                ->CAST('a.tracking_no AS UNSIGNED')
                ->order_by('date_received', 'ASC')
            ->get('document a');
        }
       
       if($query->num_rows() > 0){
           return $query->result();
       }else{
           return false;
       }
   }
Reply

#4
I don't see a cast() method in CI's query builder.
It appears to be a verb in the supported databases, so perhaps it should be added to Database\BaseBuilder?
Reply

#5
Yeah, CAST is not part of CodeIgniter's QueryBuilder, so of course it's not finding it. Did you see docs somewhere that made you think it would be there? If so, we need to revise.

That's one of MANY SQL commands that don't have a QueryBuilder equivalent, like CASE, etc. If you absolutely need to support that in the query you might have to do a straight $db->query() call (using bindings of course!), unless you can manage to make that part of a select or something which you don't escape, which you would need to be very careful with before using to make sure you didn't pass unescaped user data into.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.