Welcome Guest, Not a member yet? Register   Sign In
What's the equivalent of this PDO method in CI3
#6

You can achieve the same result in CodeIgniter 3 Query Builder with Mysqli driver using the following code:


$this->db->select('set_name, set_value');
$this->db->from('tbl_settings');
$this->db->like('set_name', 'sys_');
$query = $this->db->get();
$results = $query->result();

$sys_version = null;
foreach ($results as $result) {
if ($result->set_name == 'sys_version') {
$sys_version = $result->set_value;
break;
}
}
This code will retrieve all records from the tbl_settings table where set_name contains the string 'sys_' and return an array of objects containing the set_name and set_value columns. Then, it loops through the results to find the value for the 'sys_version' key and assigns it to the $sys_version variable.

Note that unlike the PDO method, this method requires you to loop through the results to find the desired value, as there is no built-in method to fetch key-value pairs in CodeIgniter 3 Query Builder with Mysqli driver.
Reply


Messages In This Thread
RE: What's the equivalent of this PDO method in CI3 - by GerishSonya - 04-19-2023, 11:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB