-
-
Save arunoda/9274e8505234045be61a to your computer and use it in GitHub Desktop.
Codeigniter - Interact with Database using Active Records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends CI_Controller { | |
public function __construct() { | |
parent::__construct(); | |
$this->load->database(); | |
} | |
public function insert($username, $password) { | |
$data = array( | |
"username" => $username, | |
"password" => $password | |
); | |
$this->db->insert("users", $data); | |
echo "Inserted"; | |
} | |
public function select() { | |
$result = $this->db->get("users")->result_array(); | |
$this->load->library("table"); | |
echo $this->table->generate($result); | |
} | |
public function update($username, $password) { | |
$this->db->where("username", $username); | |
$data = array("password" => $password); | |
$this->db->update("users", $data); | |
echo "Updated"; | |
} | |
public function delete($user) { | |
$this->db->where("username", $user); | |
$this->db->delete("users"); | |
echo "Deleted"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment