Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- ini_set('error_reporting', E_ALL);
- ini_set('display_startup_errors', 1);
- error_reporting(-1);
- class Database
- {
- private $host = "localhost";
- private $db_name = "test";
- private $username = "root";
- private $password = "";
- public $conn;
- public function dbConnection()
- {
- $this->conn = null;
- try
- {
- $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->conn->exec("SET CHARACTER SET `utf8`");
- }
- catch(PDOException $e)
- {
- print_r("Connection error: " . $e->__toString());
- }
- return $this->conn;
- }
- }
- $DataBase = new Database;
- $DataBase = $DataBase->dbConnection();
- class IUD
- {
- public function __construct()
- {
- $database = new Database();
- $db = $database->dbConnection();
- $this->conn = $db;
- }
- public function Insert($Tbl, $Fild, $Data)
- {
- if(is_array($Fild))
- {
- $Fild = implode(", ", $Fild);
- $Data = implode(", ", $Data);
- //print_r($Tbl."<br>".$Fild."<br>".$Data);
- $Sql = "INSERT INTO `".$Tbl."` (".$Fild.") VALUES (".$Data.")";
- $Sql = $this->conn->prepare($Sql);
- $Sql->execute();
- }
- }
- }
- $Test = new IUD;
- $Fild = array("name", "family");
- $Data = array("c","f");
- $Test->Insert("fc", $Fild, $Data);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement