summaryrefslogtreecommitdiffstats
path: root/index.example.php
diff options
context:
space:
mode:
authorIndieteq <admin@indieteq.com>2012-11-12 14:17:05 +0100
committerIndieteq <admin@indieteq.com>2012-11-12 14:17:05 +0100
commit6b98954b8040ec4cae63a2be9d79ac9bc18cd903 (patch)
treeb43ed3bc72794ff0e6279628326da670578bbefe /index.example.php
parent6691618d2b2b8c93790938e80ae94c503610950f (diff)
downloadphp-mysql-pdo-database-class-6b98954b8040ec4cae63a2be9d79ac9bc18cd903.zip
php-mysql-pdo-database-class-6b98954b8040ec4cae63a2be9d79ac9bc18cd903.tar.gz
php-mysql-pdo-database-class-6b98954b8040ec4cae63a2be9d79ac9bc18cd903.tar.bz2
SQL dump and Example PHP file
Diffstat (limited to 'index.example.php')
-rw-r--r--index.example.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/index.example.php b/index.example.php
new file mode 100644
index 0000000..71a78e0
--- /dev/null
+++ b/index.example.php
@@ -0,0 +1,47 @@
+<?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' => '31' ) );
+
+ // Single Row
+ $id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John"));
+
+ // Single Row with numeric index
+ $id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John"),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"));
+?> \ No newline at end of file