Skip to content

Commit c48f250

Browse files
committed
Created function to get db instance
1 parent 42b4b1c commit c48f250

12 files changed

+36
-12
lines changed

.phpintel/index

64 Bytes
Binary file not shown.

add_admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if ($_SERVER['REQUEST_METHOD'] == 'POST')
1515
{
1616
$data_to_store = filter_input_array(INPUT_POST);
17-
17+
$db = getDbInstance();
1818
//Password should be md5 encrypted
1919
$data_to_store['passwd'] = md5($data_to_store['passwd']);
2020
$last_id = $db->insert ('admin_accounts', $data_to_store);

add_customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$data_to_store = filter_input_array(INPUT_POST);
1212
//Insert timestamp
1313
$data_to_store['created_at'] = date('Y-m-d H:i:s');
14-
14+
$db = getDbInstance();
1515
$last_id = $db->insert ('customers', $data_to_store);
1616

1717
if($last_id)

admin_users.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
exit("401 Unauthorized");
1212
}
13+
$db = getDbInstance();
1314
//Get data from query string
1415
$search_string = filter_input(INPUT_GET, 'search_string');
1516
$del_id = filter_input(INPUT_GET, 'del_id');

authenticate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
$remember = filter_input(INPUT_POST, 'remember');
99
$passwd= md5($passwd);
1010

11-
// $query = "SELECT * FROM admin_accounts WHERE user_name='$username' AND passwd='$passwd'";
12-
// $row = $db->query($query);
11+
//Get DB instance. function is defined in config.php
12+
$db = getDbInstance();
1313

1414
$db->where ("user_name", $username);
1515
$db->where ("passwd", $passwd);

config/config.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
<?php
22

3-
//Note: This file should be include first in every php page.
3+
//Note: This file should be included first in every php page.
44

55
define('BASE_PATH', dirname(dirname(__FILE__)));
66
define('APP_FOLDER','simpleadmin');
77
define('CURRENT_PAGE', basename($_SERVER['REQUEST_URI']));
88

99

1010
require_once BASE_PATH.'/lib/MysqliDb.php';
11-
$servername = "localhost";
12-
$username = "root";
13-
$password = "";
14-
$dbname = "corephpadmin";
15-
// create connection object
16-
$db =new MysqliDb($servername,$username,$password,$dbname);
11+
12+
/*
13+
|--------------------------------------------------------------------------
14+
| DATABASE CONFIGURATION
15+
|--------------------------------------------------------------------------
16+
*/
17+
18+
define('DB_HOST', "localhost");
19+
define('DB_USER', "root");
20+
define('DB_PASSWORD', "");
21+
define('DB_NAME', "corephpadmin");
22+
23+
/**
24+
* Get instance of DB object
25+
*/
26+
function getDbInstance()
27+
{
28+
return new MysqliDb(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
29+
}

customers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
$page = filter_input(INPUT_GET, 'page');
1212
//Per page limit for pagination.
1313
$pagelimit = 20;
14+
15+
$db = getDbInstance();
1416
if (!$page) {
1517
$page = 1;
1618
}
@@ -22,6 +24,7 @@
2224
$order_by = "Desc";
2325
}
2426

27+
$db = getDbInstance();
2528
// select the columns
2629
$select = array('id', 'f_name', 'l_name', 'gender', 'phone','created_at','updated_at');
2730

delete_customer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
}
1515
$customer_id = $del_id;
16+
17+
$db = getDbInstance();
1618
$db->where('id', $customer_id);
1719
$status = $db->delete('customers');
1820

delete_user.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once 'includes/auth_validate.php';
44
require_once './config/config.php';
55
$del_id = filter_input(INPUT_POST, 'del_id');
6+
$db = getDbInstance();
67

78
if($_SESSION['admin_type']!='super'){
89
header('HTTP/1.1 401 Unauthorized', true, 401);

edit_admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
$admin_user_id= filter_input(INPUT_GET, 'admin_user_id');
8+
$db = getDbInstance();
89
//Serve POST request.
910
if ($_SERVER['REQUEST_METHOD'] == 'POST')
1011
{

0 commit comments

Comments
 (0)