Lecture 9 - Stateful Web Flashcards Preview

Web-Centric > Lecture 9 - Stateful Web > Flashcards

Flashcards in Lecture 9 - Stateful Web Deck (65)
Loading flashcards...
1

What does PDO stand for?

PHP Data Object

2

To configure the PDO to throw an exception any time there's a failure?

Use the PDO's setAttribute() method

3

What is the exec() method used for?

Queries can be sent to a MYSQL database using it.

4

What does PDO do?

Identifies that the connection to a database has been established

5

If PHP cannot handle PDO, what will it do?

Throws a php exception

6

What does the try-catch statement do?

try {
do something
}
catch (Exception type $e){
handle exception
}

7

What does this code do?

This function returns a PHP Data Object (PDO)

8

IF this PDO code can't be performed, what happens?

PHP will throw an exception

9

What does PHP do with a database once a connection is no longer needed?

It automatically disconnects

10

How do you force PHP to close a connection?

$pdo = null

11

How do you connect to a database with procedural php?

$variable_name = mysql_connect(hostname, username, password);

12

How do you close a connection to a mysql database with procedural php?

mysql_close();

13

What must be do before answering a query?

Establish a database connection

14

What are the best practices of querying a database?

Establish a connection at the start of the php script

During development, leave clues in case of issues when passing queries to the server. (relevant error messages)

15

Name three sql queries

DELETE, INSERT, UPDATE

16

PDO Method: How do we create a table?

$sql = 'CREATE TABLE jokes(id INT NOT NULLAUTO_INCREMENT PRIMARY KEY,
joketext TEXT,
jokedate DATE NOT NULL,
)

$pdo->exec($sql)

17

PDO Method: How do we update a table?

$sql = 'UPDATE joke SET jokedate = "2012" WHERE joke text LIKE "%chicken%";

$affectedRows = $pdo ->exec($sql)

18

PDO Method: How do we SELECT?

$sql = 'SELECT * FROM tablename';
$result = $pdo->query($sql);

19

What makes SELECT queries different from other queries?

They produce results

20

Procedural Method: How do we send SQL queries through php?

$variable_name = mysqli_query(sql statement);

Example:
$variable_name = mysqli_query(SELECT*FROM customers);

21

What would the result set of a query contain?

A list of all the entries returned from the query

22

Which PHP functions are needed to connect to the database using procedural php?

mysqli_connect()
mysql_set_chart()
mysqli_select_db()

23

What does mysqli_connect() do?

Connects to the database

24

What does mysql_set_chartset() do?

Indicates the character set to be used for
communications between PHP and the DB

Must match the character set used by HTML pages,
DB and its tables

25

What does mysql_select_db() do?

Indicates the database to be used for queries.

26

How would you add a new joke from a user, using php?

if (isset($_GET['addjoke']))
{
include 'form.html.php';
exit()

27

When deleting a record, how will we identify which once we want removed?

By it's ID

28

Can vars in the main script be accessed or edited from an included file?

Yes. is can cause issues likes overwrites. Functions can protect you from this happening.

29

What is a function's scope?

Variables created inside a function exist only in that function

30

Can vars from the mains script by accessed from within functions?

No.