· 8 years ago · Mar 15, 2018, 09:02 AM
1<?php
2
3
4class Database{
5
6 private $host = "localhost";
7 private $db_name = "kkeeda";
8 private $username = "root";
9 private $password = "123456789";
10 public $conn;
11
12 public function getConnection(){
13
14 $this->conn = null;
15
16 try {
17 $this->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->db_name, $this->username, $this->password);
18 } catch (PDOException $exception) {
19 echo "Connection Error! ". $exception->getMessage();
20 }
21
22 return $this->conn;
23 }
24}
25
26
27$database = new Database();
28$db = $database->getConnection();
29
30$query = "CREATE TABLE IF NOT EXISTS test (
31 id INT(11),
32 Imie VARCHAR(30),
33 Nazwisko VARCHAR(30)
34
35);";
36
37$stmt = $db->prepare($query);
38$stmt->execute();
39
40?>