Create Config File In PDO
<?php
$db = array('host' => 'localhost',
'username'=>'root',
'password'=>'',
'dbname'=>'geltos'
);
$database= new PDO('mysql:host='.$db['host'].';dbname='.$db['dbname'],$db['username'],$db['password']);
$database->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
?>
Create Classes
<?php
class Product
{
private $db;
public function __construct($db)
{
$this->db = $db;
}
private function insertId($table, $column, $id)
{
$query=$this->db->prepare("INSERT INTO $table set $column =? ");
$query->bindValue('1',$id);
$query->execute();
}
public function checkProduct($prodname,$catid ,$subcatid)
{
$query=$this->db->prepare("SELECT count(pro_id) FROM product WHERE pro_name =? and pro_cat_id = ? and pro_subcat_id =? ");
$query->bindValue(1,trim($prodname));
$query->bindValue(2,trim($catid));
$query->bindValue(3,trim($subcatid));
try
{
$query->execute();
$getrows=$query->fetchColumn();
if($getrows>0)
{
return true;
}
else
{
return false;
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function checkProductAttr($table, $id, $where)
{
$par = array_keys($where);
$parkey = $par[0];
$query=$this->db->prepare("SELECT count($id) FROM $table WHERE $parkey =? ");
$query->bindValue(1,$where[$parkey]);
try
{
$query->execute();
$getrows=$query->fetchColumn();
if($getrows>0)
{
return $getrows;
}
else
{
return 0;
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
Create Objects Of classes or file init.php
<?php
ob_start();
session_start();
header ("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
error_reporting(0);
require 'config/config.php';
require 'classes/user.php';
require 'classes/category.php';
require 'classes/product.php';
$product = new Product($database);
$cat = new Category($database);
$cart = new Cart($database);
$user = new User($database);
$site_name = 'GELTOS';
$site_url = 'http://techmobile.com/dev/cuttingsolutionsusa/';
$page_url = $site_url.basename($_SERVER['PHP_SELF']);
$sess_id = session_id();
$months = array("1" => "Gennaio","2" => "Febbrio","3" => "Marzo","4" => "Aprile","5" => "Maggio","6" => "Giugno","7" => "Luglio","8" => "Agosto","9" => "Settembre","10" => "Ottobre","11" => "Novembre","12" => "Dicembre");
function ttruncat($text,$numb) {
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$etc = " ...";
$text = $text.$etc;
}
return $text;
}
clearstatcache();
?>
<?php
$db = array('host' => 'localhost',
'username'=>'root',
'password'=>'',
'dbname'=>'geltos'
);
$database= new PDO('mysql:host='.$db['host'].';dbname='.$db['dbname'],$db['username'],$db['password']);
$database->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
?>
Create Classes
<?php
class Product
{
private $db;
public function __construct($db)
{
$this->db = $db;
}
private function insertId($table, $column, $id)
{
$query=$this->db->prepare("INSERT INTO $table set $column =? ");
$query->bindValue('1',$id);
$query->execute();
}
public function checkProduct($prodname,$catid ,$subcatid)
{
$query=$this->db->prepare("SELECT count(pro_id) FROM product WHERE pro_name =? and pro_cat_id = ? and pro_subcat_id =? ");
$query->bindValue(1,trim($prodname));
$query->bindValue(2,trim($catid));
$query->bindValue(3,trim($subcatid));
try
{
$query->execute();
$getrows=$query->fetchColumn();
if($getrows>0)
{
return true;
}
else
{
return false;
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function checkProductAttr($table, $id, $where)
{
$par = array_keys($where);
$parkey = $par[0];
$query=$this->db->prepare("SELECT count($id) FROM $table WHERE $parkey =? ");
$query->bindValue(1,$where[$parkey]);
try
{
$query->execute();
$getrows=$query->fetchColumn();
if($getrows>0)
{
return $getrows;
}
else
{
return 0;
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
Create Objects Of classes or file init.php
<?php
ob_start();
session_start();
header ("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
error_reporting(0);
require 'config/config.php';
require 'classes/user.php';
require 'classes/category.php';
require 'classes/product.php';
$product = new Product($database);
$cat = new Category($database);
$cart = new Cart($database);
$user = new User($database);
$site_name = 'GELTOS';
$site_url = 'http://techmobile.com/dev/cuttingsolutionsusa/';
$page_url = $site_url.basename($_SERVER['PHP_SELF']);
$sess_id = session_id();
$months = array("1" => "Gennaio","2" => "Febbrio","3" => "Marzo","4" => "Aprile","5" => "Maggio","6" => "Giugno","7" => "Luglio","8" => "Agosto","9" => "Settembre","10" => "Ottobre","11" => "Novembre","12" => "Dicembre");
function ttruncat($text,$numb) {
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$etc = " ...";
$text = $text.$etc;
}
return $text;
}
clearstatcache();
?>
EmoticonEmoticon