M
M
Maria Popova2019-11-26 09:37:16
MySQL
Maria Popova, 2019-11-26 09:37:16

CodeIgniter create exact query?

I create a request with parameters

this->db->get_where( 'contacts', array( 'customer_id' => $id ) )->result_array();

It returns slightly inaccurate data, for example: customer_id=7, records come in with customer_id 7, 17, 27.
I try like this:
this->db->get_where( 'contacts', array( 'customer_id' => $id ) )->row_array();

nothing changes.
If customer_id=10 and above it works fine.
Tell me where is something wrong, where to dig?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Buksha, 2019-11-26
@masha_0212

Try using the where() method

A
Alams Stoyne, 2019-11-26
@alams_stoyne

And in the Database itself, does customer_id have an INT type or something else?

O
Oleg, 2019-11-26
@402d

In my opinion, your request looks completely different from what you think.
echo $this->db->last_query();
The codeignitor query builder has an unpleasant feature.
$this->db->something
and if you type it somewhere in a function in parts, and then decide that you
don’t need to call get or get_where, then the garbage will be attached to the next request.
There is even a method.
$this->db->reset_query()
Resetting Query Builder allows you to start fresh with your query without executing it first using a method like $this->db->get() or $this->db->insert() . Just like the methods that execute a query, this will not reset items you've cached using Query Builder Caching

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question