CodeIgniter Forums
I found issue with db driver - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: I found issue with db driver (/showthread.php?tid=1132)



I found issue with db driver - Vimal - 02-13-2015

I am using pdo driver and my query is
PHP Code:
$query $this->db->select()->from('community_list')->where('community_name',$community);
        
$rows $query->num_rows(); 

Its show me error like

Code:
Severity: Notice

Message: Array to string conversion

Filename: database/DB_query_builder.php

Line Number: 662



RE: I found issue with db driver - Vimal - 02-13-2015

And Also for this query
PHP Code:
$c = array(
'community' => $community
);
$query $this->db->get_where('community_list'$c); 



RE: I found issue with db driver - Rufnex - 02-13-2015

Have you done a var_dump on $community .. maybe you have wrong data.


RE: I found issue with db driver - Vimal - 02-13-2015

No. its not.


RE: I found issue with db driver - twpmarketing - 02-15-2015

Vimal,
 The syntax of the where() clause is the problem.
From the User Guide (v. 3.0):

http://www.codeigniter.com/userguide3/database/query_builder.html#looking-for-specific-data

You can pass an associative array directly in the where() clause.  However your code assigns an variable ($community) to a column name ('community_name').  Because the column type is probably string, the error is generated when you assign an array ($community) to that string var.


Code:
where('community_name',$community)

I think you want to use either the  where_in() OR or_where_in() clause.  They are explained a few paragraphs below the User Guide link above.  Note that the array is NOT associative in this usage.

Quote:$this->db->or_where_in()


Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with OR if appropriate

$names = array('Frank', 'Todd', 'James');
$this->db->or_where_in('username', $names);

// Produces: OR username IN ('Frank', 'Todd', 'James')