Welcome Guest, Not a member yet? Register   Sign In
Get data in type from DB
#1

class Wages {

protected BaseConnection $db;

public function __construct() {
$this->db = Database::connect();
}

public function get (): array {

return $this->db->table('wage')
->where('office', 2)
->orderBy('title')
->get()
->getResultArray();

}

}

I have model like this, how can i get data by types, not like string

I should do like this

<?php namespace App\Entities;

use CodeIgniter\Entity\Entity;

class Wage extends Entity {

protected $casts = [
'id' => 'integer',
'title' => 'string',
'office' => 'integer'
];

}
Reply
#2

Type conversion depends on the capabilities of the DBMS driver.
As far as I know, only mysql native driver (mysqlnd) can provide data types from the database.
Actually, this is why all frameworks use their own type conversion.

Why don't you like using Entity?
Why an array?
Reply
#3

(03-24-2023, 02:58 AM)iRedds Wrote: Type conversion depends on the capabilities of the DBMS driver.
As far as I know, only mysql native driver (mysqlnd) can provide data types from the database.
Actually, this is why all frameworks use their own type conversion.

Why don't you like using Entity?
Why an array?


OK how can i get any SQL query in cast?

Like this one?

$this->db->table('wage')
->where('office', 2)
->orderBy('title')
->get()
->getResultArray();

and how if i have few tables?


$this->db->table('wage as w, kinds as k')
->where('office', 2)
->where('w.kind = k.id')
->orderBy('title')
->get()
->getResultArray();
Reply
#4

See https://codeigniter4.github.io/CodeIgnit...tom-object
Reply




Theme © iAndrew 2016 - Forum software by © MyBB