-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_crud_singleton.php
More file actions
89 lines (61 loc) · 2.21 KB
/
basic_crud_singleton.php
File metadata and controls
89 lines (61 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
include "DB.php";
class Basic_CRUD {
//this is created when its object is initialized
function __construct() {
//to test if singleon pattern ahs been implemented or not.
//DB::get()->handle();
DB::geat();
}
function insert_CRUD($post_variables = "") {
//var_dump($post_variables); die;
$this->sql = "INSERT INTO tbl_details SET name = '".$post_variables['name']."', age = '".$post_variables['age']."' ";
$this->result = mysql_query($this->sql);
if($this->result) {
return mysql_insert_id();
}
}//function close
function update_CRUD($post_variables = "") {
//var_dump($post_variables); die;
//to check what query i am running
//echo $this->sql = "UPDATE tbl_details SET name = '".$post_variables['name']."', age = '".$post_variables['age']."' WHERE id ='".$post_variables['id']."'"; die;
$this->sql = "UPDATE tbl_details SET name = '".$post_variables['name']."', age = '".$post_variables['age']."' WHERE id ='".$post_variables['id']."'";
return $this->result = mysql_query($this->sql);
}
public function display_crud($id = "") {
$this->sql = "SELECT * FROM core_users";
//checking if any id is sent
// this is done for getting value in edit
if($id!=""){
$this->sql.=" WHERE id='".$id."'";
}
//for checking what queryi am runnings
//echo $this->sql; die;
$this->result = mysql_query($this->sql);
//var_dump(mysql_fetch_array($this->result)); die;
$return_result_array =array();
$return_list = array();
if($this->result) {
while($row = mysql_fetch_array($this->result)) {
$return_result_array['id'] = $row['id'];
$return_result_array['email'] = $row['email'];
//$return_result_array['password'] = $row['passsword'];
array_push($return_list, $return_result_array);
}
}
return $return_list;
}
function delete_CRUD($id = "") {
$this->sql = "DELETE FROM tbl_details WHERE id='".$id."'";
return $this->result = mysql_query($this->sql);
}
}
//echo DB::get()->handle();
$crud_obj = new Basic_CRUD();
var_dump($crud_obj->display_crud());
//var_dump($crud_obj);
echo "<br />";
//echo DB::get()->handle();
$crud_obj2 = new Basic_CRUD();
var_dump($crud_obj2->display_crud());
?>