From c41a44ad13fa9143596869f0791c9ccd95a3f8ac Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 1 Jan 2011 11:14:12 -0500 Subject: [PATCH] making pdo version of mysql stuff --- docroot/html/pdo.php | 152 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 docroot/html/pdo.php diff --git a/docroot/html/pdo.php b/docroot/html/pdo.php new file mode 100644 index 0000000..0bb5ea3 --- /dev/null +++ b/docroot/html/pdo.php @@ -0,0 +1,152 @@ +getMessage()); + exit(); +} + +$ACTION = ""; + +if (array_key_exists("action", $_POST)) { + $ACTION = $_POST["action"]; +} + + +require_once("_head.php"); + + +function show_clear_link() { + ?> + clear + + + + +

Creating tables...

exec("DROP TABLE IF EXISTS customers");
+
+        try {
+            $nrows = $PDOCONN->exec("
+                CREATE TABLE customers (
+                    customer_id MEDIUMINT NOT NULL AUTO_INCREMENT,
+                    name VARCHAR(255) NOT NULL,
+                    email VARCHAR(255) NOT NULL,
+                    PRIMARY KEY(customer_id)
+                ) ENGINE=InnoDB
+            ");
+
+            printf("%d Row inserted.\n", $nrows);
+
+        } catch (PDOException $e) {
+            printf("Failed to create tables: \n%s\n", $e->getMessage());
+        }
+
+        ?>
+ +
prepare( + "INSERT INTO customers (customer_id, name, email) VALUES (NULL, :name, :email)" + ); + $add_customer->bindParam(':name', $_POST["name"], PDO::PARAM_STR, 12); + $add_customer->bindParam(':email', $_POST["email"], PDO::PARAM_STR, 12); + $nrows = $add_customer->execute(); + + ?>

Row inserted.

Failed to create customer!: getMessage() ?>

+ +
+
+ Database Admin + + + + + + + + + + + + + +
+
+ +
+
Add Customer + + + + + + + + + + +
+
+ + +
query("SELECT * FROM customers");
+            while ($row = $results->fetchAll()) {
+                print_r($row);
+            }
+        ?>
+ + + + + + +