Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connection {
- public $connection;
- public $dbHost = 'localhost';
- public $dbName = 'employees';
- public $charset = 'charset=utf8';
- public $dbUser = 'root';
- public $dbPassword = '';
- public function __construct() {
- try {
- $this->connection = new PDO ("mysql:host=$this->dbHost;$this->dbName;$this->dbUser;
- $this->dbPassword");
- $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch (PDOException $e) {
- echo "There is something wrong with the database".$e->getMessage();
- }
- }
- function insertUserValues($tableName, $data) {
- $query = "INSERT INTO ".$tableName."(";
- $query .= implode (",",array_keys($data)).') VALUES (';
- $query .= "'" . implode ("','",array_values($data))."')";
- }
- }
- $users = new Connection();
- ?>
- <?php
- $dbhost = "localhost";
- $dbname = "pdo";
- $dbusername = "root";
- $dbpassword = "845625";
- $link = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $statement = $link->prepare("INSERT INTO testtable(name, lastname, age)
- VALUES(:fname, :sname, :age)");
- $statement->execute(array(
- "fname" => "Bob",
- "sname" => "Desaunois",
- "age" => "18"
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement