db ayarları ve select
1)
database.php parametrelerini doldur.
bağlanma sorunu olursa "dbdriver" parametresini mysqli'ye çevir.
2)
autoload.php dosyasında
$autoload["libraries"] = array("database"); 'e çevir
sorgu sisteminin adı "active record"...
https://codeigniter.com/userguide2/database/active_record.html
tablonun tüm satırlarını çekmek için
$rows = $this->db->get("customers")->result();
sonuçlardan tek satır çekmek için
$rows = $this->db->get("customers")->row();
view'da yazdırmak için
<?php foreach ($row as $row) {?>
<?php echo $row->first_name; ?>
<?php }?>
sorgu çekmek için
$rows = $this->db->where("first_name", "Doğan")->get("customers")->result();
veya
$rows = $this->db->where("age >", 10)->where("budget >", 10000)->get("customers")->result();
veya
$rows = $this->db->where("vip !=", true)->get("customers")->result();
aynı işi
$conditions = array(
"id >" => 5,
"first_name", "dogancoruh@gmail.com"
);
$rows = $this->db->where($conditions)->get("customers")->result();
or_where kullanmak için
$rows = $this->db->or_where($conditions)->get("customers")->result();
where_in kullanmak için
$rows = $this->db->where_in("first_name", array("Doğan", "Cüneyt"))->get("customers")->result();
database.php parametrelerini doldur.
bağlanma sorunu olursa "dbdriver" parametresini mysqli'ye çevir.
2)
autoload.php dosyasında
$autoload["libraries"] = array("database"); 'e çevir
sorgu sisteminin adı "active record"...
https://codeigniter.com/userguide2/database/active_record.html
tablonun tüm satırlarını çekmek için
$rows = $this->db->get("customers")->result();
sonuçlardan tek satır çekmek için
$rows = $this->db->get("customers")->row();
view'da yazdırmak için
<?php foreach ($row as $row) {?>
<?php echo $row->first_name; ?>
<?php }?>
sorgu çekmek için
$rows = $this->db->where("first_name", "Doğan")->get("customers")->result();
veya
$rows = $this->db->where("age >", 10)->where("budget >", 10000)->get("customers")->result();
veya
$rows = $this->db->where("vip !=", true)->get("customers")->result();
aynı işi
$conditions = array(
"id >" => 5,
"first_name", "dogancoruh@gmail.com"
);
$rows = $this->db->where($conditions)->get("customers")->result();
or_where kullanmak için
$rows = $this->db->or_where($conditions)->get("customers")->result();
where_in kullanmak için
$rows = $this->db->where_in("first_name", array("Doğan", "Cüneyt"))->get("customers")->result();
Yorumlar
Yorum Gönder