Presentation is loading. Please wait.

Presentation is loading. Please wait.

PDO and Arrays MIS 3502 Jeremy Shafer Department of MIS

Similar presentations


Presentation on theme: "PDO and Arrays MIS 3502 Jeremy Shafer Department of MIS"— Presentation transcript:

1 PDO and Arrays MIS 3502 Jeremy Shafer Department of MIS
Fox School of Business Temple University

2 Roadmap We are here. Part 2 JavaScript jQuery Part 1 MVC PDO Bootstrap
Ajax, JSON APIs

3 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 Discuss different kinds of arrays

4 Opening a database connection
The syntax for executing a method of any object $objectName->methodName(argumentList) What’s the meaning of this?

5

6 What’s the purpose of this line?
Tip! What’s the purpose of this line?

7

8 Remember the order: prepare bindValue Execute

9 Using the question mark placeholder instead of a named placeholder.
Tip! Using the question mark placeholder instead of a named placeholder.

10 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 It’s a mantra!

11 What is an array? An array is a data type that can contain one or more items called elements. Each element stores a value that you can refer to with an index. The length of the array indicates the number of elements that it contains. In short, an array is a structure that allows us to store multiple pieces of similar data.

12 One Dimensional Array [0] [1] [2] [‘first’] [‘last’] [‘id’] ‘Mike’
‘Murach’ ‘6453’ [‘first’] [‘last’] [‘id’] ‘Mike’ ‘Murach’ ‘6453’

13 Where do arrays come from?

14

15 Retrieves multiple database records as a two dimensional array.
Remember the order: prepare bindValue execute fetchAll closeCursor

16 Multidimensional Arrays

17 Can be hard to read…

18 Some folks think this is easier to read…

19 INSERT Tip!

20 UPDATE

21 DELETE

22 A handy function… Let’s try that…

23 Some fetchAll options PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0 And.. there are others. But these three you should know. If you want to know more:

24 Next time we will…


Download ppt "PDO and Arrays MIS 3502 Jeremy Shafer Department of MIS"

Similar presentations


Ads by Google