-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
101 lines (87 loc) · 3.15 KB
/
test.php
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
90
91
92
93
94
95
96
97
98
99
100
101
<?php
ob_start();
session_start();
define("DB_HOST", "localhost");
define("DB_NAME", "ohi_telecom");// Change your database name
define("DB_USER", "root");// Your database user id
define("DB_PASS", ""); // Your password
define("TABLEPREFIX", "ohi_"); # Mysql Database Table Prefix
//folder paths
define('HOST','http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}");
define('CUR_URL',HOST. $_SERVER['REQUEST_URI']); //directory
define('DIR_PATH',HOST. dirname($_SERVER['REQUEST_URI'])); //directory
define('DIR_ADMIN', 'dashboard/ohi/admin/'); // absolute path for admin
define('DIR_UPLOADS', '/ohi_tele/dashboard/ohi/admin/uploads/'); // absolute path for admin
define('DIR_PDT_IMAGES', '/ohi_tele/dashboard/ohi/admin/uploads/products/'); // absolute path for admin
define('HTTP_SERVER',HOST.'/ohi_tele'); // eg, HOST or - http://localhost, should not be NULL for productive servers
define('ADMIN_EMAIL','[email protected]');//should change to user mail id
$home = "";
$about = "";
//Database Connection
try
{
$DB_con = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER,DB_PASS);//(host;dbname,dbuser,dbpass)
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$DB_con->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);//to avoid quote numeric arguments
$DB_con->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, TRUE);
}
catch(PDOException $exception)
{
die('Database Connection Failed: ' . $exception->getMessage());
}
class Techsoft
{
private $dbh;
private $error;
//Database Connection
public function __construct($DB_con)
{
$this->dbh = $DB_con;
}
//function to select values from a table
public function select_rows($table,$fieldlist,$condition,$data)
{
$stmt = $this->dbh->prepare("SELECT $fieldlist FROM $table $condition");
$stmt->execute($data);
//$stmt->debugDumpParams();
return $stmt;
}//end function
//function to insert values in a table
public function insert_fields($table,$fieldlist,$values,$data)
{
$stmt = $this->dbh->prepare("INSERT into $table ($fieldlist) values($values)");
$stmt->execute($data);
return $stmt;
}//end function
//function to update values in a table
public function update_rows($table,$fieldlist,$condition,$data)
{
$stmt = $this->dbh->prepare("UPDATE $table set $fieldlist $condition");
$stmt->execute($data);
return $stmt;
}//end function
//function for deleting values from table
public function delete_rows($table,$condition,$data)
{
$stmt = $this->dbh->prepare("DELETE FROM $table $condition");
$stmt->execute($data);
return $stmt;
}
}//end class
$objA = new Techsoft($DB_con);
$sessionId = session_id();
$cond_select_news = "ORDER BY NEWS_ID DESC LIMIT ?,?";
$data_select_news = array(0,3);
$pass_select_news = $objA->select_rows(TABLEPREFIX.'news','*',$cond_select_news,$data_select_news);
if($pass_select_news->rowCount()>0)
{
while($arr_news = $pass_select_news->fetch(PDO::FETCH_ASSOC))
{
echo $arr_news['NEWS_TITLE']."<br>";
}
}
else
{
echo "No records found!";
}
?>