Welcome Guest, Not a member yet? Register   Sign In
CI4 $this-db->Table() inside foreach or outside
#6

(11-04-2021, 11:31 AM)objecttothis Wrote:
PHP Code:
$builder $this->db->table('foo_table');
$result $builder->get();    //After this get() call the $builder instance is "reset" and free to use again? 

Yes. It's default behavior.
From your example: after get() method executed "select" part is clear again, BUT "from" part of your builder is still "foo_table".
So if you planning to continue to work with foo_table, you can.

(11-04-2021, 11:31 AM)objecttothis Wrote:
PHP Code:
$builder->where('item_id');
$builder->where('definition_id'$definition_id);
$builder->delete();    //This will work just fine as long as I'm wanting to run the delete against the same table? 

YES.
In your example "where" is a clause, so it's NEED key/value pair. So the first row of code is wrong.
After "where" clause and delete() method execution builder will reset "where" clause part of query.

(11-04-2021, 11:31 AM)objecttothis Wrote: Am I correct that if I wanted to run the $builder->delete() against another table I would just need to place $builder = $this->db->table('bar_table'); after the $builder->get() call and before the $builder->where()?

If you need to work with another table, get query builder with another name of table like
$barTableBuilder = $this->db->table('bar_table');
Reply


Messages In This Thread
RE: CI4 $this-db->Table() inside foreach or outside - by manager - 11-04-2021, 10:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB