Created
August 19, 2014 04:47
-
-
Save dukenmarga/1ce309732e7efe5c90df to your computer and use it in GitHub Desktop.
Simple Crud in PHP
This file contains hidden or 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 | |
| function insert($table = '1', $values = array(' ' => ' ')){ | |
| if (is_array($values)){ | |
| foreach($values as $value){ | |
| $field .= "$value,"; | |
| } | |
| } | |
| $val = str_replace(',', '', $val); | |
| $query = "INSERT INTO $table VALUES ($val)"; | |
| $this->exec($query); | |
| } | |
| function delete($table = '1', $condition = array(' ' => ' ')){ | |
| foreach ($condition as $key => $value) | |
| $where .= " $key='$value' "; | |
| } | |
| $where = str_replace(',', '', $where); | |
| $where = str_replace('AND', '', $where); | |
| $where = str_replace('OR', '', $where); | |
| $query = "DELETE FROM $table WHERE $where"; | |
| $this->exec($query); | |
| } | |
| function update($table = '1', $set $condition = array(' ' => ' ')){ | |
| foreach ($condition as $key => $value){ | |
| $set .= " $key='$value', " | |
| } | |
| $set = str_replace(',', '', $set); | |
| foreach ($condition as $key => $value) | |
| $where .= " $key='$value' "; | |
| } | |
| $where = str_replace(',', '', $where); | |
| $where = str_replace('AND', '', $where); | |
| $where = str_replace('OR', '', $where); | |
| $query = "UPDATE $table SET $set WHERE $where"; | |
| $this->exec($query); | |
| } | |
| function run(){ | |
| $sql = $this->sql; | |
| $sql->execute($query); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment