Skip to content

Instantly share code, notes, and snippets.

@dukenmarga
Created August 19, 2014 04:47
Show Gist options
  • Select an option

  • Save dukenmarga/1ce309732e7efe5c90df to your computer and use it in GitHub Desktop.

Select an option

Save dukenmarga/1ce309732e7efe5c90df to your computer and use it in GitHub Desktop.
Simple Crud in PHP
<?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