PDO Revisited MIS 3502 Jeremy Shafer Department of MIS Fox School of Business Temple University
Roadmap We are here.
Agenda Old business New business Review code which opens a PDO database connection Review the PDO methods – prepare, bindvalue, execute, fetch, fetchAll, closecursor Review sample code which executes SELECT, INSERT, UPDATE and DELETE statements New business A tip for managing errors An alternative to named placeholders The lastInsertId method
Opening a database connection The syntax for executing a method of any object $objectName->methodName(argumentList) What’s the meaning of this?
What’s the purpose of this line? Tip! What’s the purpose of this line?
Remember the order: prepare bindValue Execute
Using the question mark placeholder instead of a named placeholder. Tip! Using the question mark placeholder instead of a named placeholder.
Retrieves one database record as a one dimensional array. SELECT Retrieves one database record as a one dimensional array. Remember the order: prepare bindValue execute fetch closeCursor
Retrieves multiple database records as a two dimensional array. Remember the order: prepare bindValue execute fetchAll closeCursor
Can be hard to read…
Slightly easier to read…
INSERT Tip!
UPDATE
DELETE
Let’s see what we can build…