Slide 1

Slide 1 text

PHP & MySQL: PDO x MySQLi Marcos Marcolin

Slide 2

Slide 2 text

Script ● Introduction; ● Comparison; ● Examples; ● Kahoot!.

Slide 3

Slide 3 text

PHP Data Objects (PDO) ● Native Module with PHP > 5; ● Object Oriented Paradigm; ● Relational Database; ● Interface; ● Abstraction Layer; ● Not rewrite queries;

Slide 4

Slide 4 text

Abstract

Slide 5

Slide 5 text

Supported Drivers

Slide 6

Slide 6 text

Supported Drivers

Slide 7

Slide 7 text

Enabling the extension (php.ini) Linux Windows

Slide 8

Slide 8 text

Available Drivers

Slide 9

Slide 9 text

Start connection

Slide 10

Slide 10 text

getInstance()

Slide 11

Slide 11 text

insertUser()

Slide 12

Slide 12 text

deleteUser()

Slide 13

Slide 13 text

listAllUsers

Slide 14

Slide 14 text

SGBD’s

Slide 15

Slide 15 text

PDO::Exceptions

Slide 16

Slide 16 text

setFetchMode()

Slide 17

Slide 17 text

PDO x MySQLi

Slide 18

Slide 18 text

getConnect()

Slide 19

Slide 19 text

Named Parameters

Slide 20

Slide 20 text

Database Migration (mysql -> pg)

Slide 21

Slide 21 text

Database Migration (mysql -> pg)

Slide 22

Slide 22 text

Database Migration (mysql -> pg)

Slide 23

Slide 23 text

Security / Prepared Statements

Slide 24

Slide 24 text

Security / Prepared Statements

Slide 25

Slide 25 text

Security / Prepared Statements ● Pre-prepared queries; ● Split data entry;

Slide 26

Slide 26 text

Security / Prepared Statements

Slide 27

Slide 27 text

Security / Prepared Statements

Slide 28

Slide 28 text

Security / Prepared Statements ● PDO : using client-side (emulating); ● MySQLi: using server-side.

Slide 29

Slide 29 text

Security / Prepared Statements ● PDO : using client-side (emulating); ● MySQLi: using server-side. Client-side Server-side

Slide 30

Slide 30 text

Transactions ● PDO ::beginTransaction(); ● PDO ::commit(); ● PDO ::rollBack();

Slide 31

Slide 31 text

Transactions ● PDO ::beginTransaction(); ● PDO ::commit(); ● PDO ::rollBack() ● Properties: ○ atomicity; ○ consistency; ○ isolation; ○ durability.

Slide 32

Slide 32 text

Class PDO

Slide 33

Slide 33 text

References ● https://www.php.net/manual/pt_BR/book.pdo.php ● https://www.php.net/manual/pt_BR/class.pdo.php ● https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection ● http://miscelaneadoconhecimento.com/mysql/sql/pdo.html ● https://code.tutsplus.com/pt/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059 ● https://php.net/manual/pt_BR/book.mysqli.php