Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connection
- {
- private $conn;
- private $host;
- private $username;
- private $password;
- private $database;
- private $port;
- private $debug;
- private $attributes;
- function Connection($params=array())
- {
- //error_reporting(0);
- $this->conn = false;
- $this->host ='localhost';
- $this->username ='root';
- $this->password ='';
- $this->database ='easyway';
- $this->port = '';
- $this->debug = true;
- $attributes=array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
- );
- $this->connect();
- session_start();
- }
- function __destruct()
- {
- //$this->Close();
- }
- function connect() //connection
- {
- if (!$this->conn) {
- try {
- $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->database.'', $this->username, $this->password, $this->attributes);
- }
- catch (Exception $e) {
- die('Error : ' . $e->getMessage());
- echo"Connect Error";
- }
- if (!$this->conn) {
- $this->status_fatal = true;
- echo 'Connection failed';
- die();
- }
- else {
- $this->status_fatal = false;
- }
- }
- return $this->conn;
- }
- function Close()
- {
- if ($this->conn) {
- $this->conn = null;
- }
- }
- }
- class Insertion extends Connection
- {
- function Insertion($tablename,$data,$other)
- {
- $conn=parent::connect();
- $fields = array_keys($data);
- echo $sql = "INSERT INTO ".$tablename."
- (`".implode('`,`', $fields)."`)
- VALUES('".implode("','", $data)."');";
- $prepared=$conn->prepare($sql);
- $prepared->execute($data);
- print_r($prepared->errorInfo());
- //print_r($prepared->errorCode());
- }
- function page_redirect($other)
- {
- extract($other);
- print_r($other);
- echo $page;
- header("location:$page.php?$message");
- }
- }
- ?>
- =============================Invoking Page===============================
- Array ( [0] => 3D000 [1] => 1046 [2] => No database selected )
Add Comment
Please, Sign In to add comment