diff options
-rw-r--r-- | Db.class.php | 2 | ||||
-rw-r--r-- | composer.json | 6 | ||||
-rw-r--r-- | index.php | 60 |
3 files changed, 1 insertions, 67 deletions
diff --git a/Db.class.php b/Db.class.php index 7494a7a..cf0e4d8 100644 --- a/Db.class.php +++ b/Db.class.php @@ -57,7 +57,7 @@ class DB try { # Read settings from INI file, set UTF8 - $this->pdo = new PDO($dsn, $ettings["dbuser"], $settings["dbpass"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); + $this->pdo = new PDO($dsn, $settings["dbuser"], $settings["dbpass"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); # We can now log any exceptions on Fatal error. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); diff --git a/composer.json b/composer.json deleted file mode 100644 index 0db4daf..0000000 --- a/composer.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "jayc89/PHP-MySQL-PDO-Database-Class", - "require": { - "php": ">=5.3.0" - } -} diff --git a/index.php b/index.php deleted file mode 100644 index 623cb9a..0000000 --- a/index.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - require("Db.class.php"); - - // Creates the instance - $db = new Db(); - - // 3 ways to bind parameters : - - // 1. Read friendly method - $db->bind("firstname","John"); - $db->bind("age","19"); - - // 2. Bind more parameters - $db->bindMore(array("firstname"=>"John","age"=>"19")); - - // 3. Or just give the parameters to the method - $db->query("SELECT * FROM Persons WHERE firstname = :firstname AND age = :age", array("firstname"=>"John","age"=>"19")); - - // Fetching data - $person = $db->query("SELECT * FROM Persons"); - - // If you want another fetchmode just give it as parameter - $persons_num = $db->query("SELECT * FROM Persons", null, PDO::FETCH_NUM); - - // Fetching single value - $firstname = $db->single("SELECT firstname FROM Persons WHERE Id = :id ", array('id' => '3' ) ); - - // Single Row - $id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe")); - - // Single Row with numeric index - $id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe"),PDO::FETCH_NUM); - - // Column, numeric index - $ages = $db->column("SELECT age FROM Persons"); - - // The following statemens will return the affected rows - - // Update statement - $update = $db->query("UPDATE Persons SET firstname = :f WHERE Id = :id",array("f"=>"Johny","id"=>"1")); - - // Insert statement -// $insert = $db->query("INSERT INTO Persons(Firstname,Age) VALUES(:f,:age)",array("f"=>"Vivek","age"=>"20")); - - // Delete statement -// $delete = $db->query("DELETE FROM Persons WHERE Id = :id",array("id"=>"6")); - - function d($v,$t) - { - echo '<pre>'; - echo '<h1>' . $t. '</h1>'; - var_dump($v); - echo '</pre>'; - } - d($person, "All persons"); - d($firstname, "Fetch Single value, The firstname"); - d($id_age, "Single Row, Id and Age"); - d($ages, "Fetch Column, Numeric Index"); - -?> |