Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class db {
- private $dsn = 'mysql:host=127.0.0.1;dbname=users';
- private $username = 'root';
- private $password = '';
- public $dbh;
- public function __construct(){
- $this->conn();
- }
- public function conn(){
- try {
- $this->dbh = new PDO($this->dsn, $this->username, $this->password);
- $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- } catch (PDOException $e) {
- echo "Database Connection failed because: " . $e->getMessage() . "<br/>";
- die();
- }
- }
- public function run_query($name, $email) {
- try{
- $stmt = $this->dbh->prepare ("INSERT INTO users (name, email) VALUES (:name, :email)");
- /*$stmt -> bindParam(':name', $name, PDO::PARAM_STR, 12);
- $stmt -> bindParam(':email', $email, PDO::PARAM_STR, 12);*/
- $stmt->execute(array($name, $email));
- } catch (PDOException $e) {
- echo 'Query failed : '. $e->getMessage;
- }
- }
- }
- $conn = new db;
- $conn->run_query('Dotun', 'dotunoyesanmi@gmail.com');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement