What is used by PHP to connect to MySQL database server?
Front
PHP extension
Back
required data to establish DB connection:
Front
host
db username
db password
db name
Back
what does all php code go between?
Front
<?php
?>
Back
name 3 characteristics of variables:
Front
start with a dollar sign
start with letter or underscore
case-sensitive
Back
When should you use the POST METHOD:
Front
security (passwords, etc.)
sending large amount of data
usually used to insert/update data
Back
What code returns a "table" of results?
Front
$mysqli->query()
Back
How do you display results? code it
Front
output number of rows in the result:
echo "there are" . $results->num_rows . "results.";
Loop through all results:
while( $row = $results->fetch_assoc() ) {
echo $row['name'];
}
Back
MySQLi / PHP extension workflow:
Front
establish DB connection
submit SQL query
display results
close DB connection
Back
code for array of HTTP POST variable:
Front
$_POST['variable'];
Back
are functions and keywords case-sensitive?
Front
no
Back
code for array with server and environment information:
HTTP GET METHOD,
where does it submit all form data?
we use the $_GET associative array to?
What does the array key correspond to?
Front
url
access data
name attribute value
Back
what is php?
Front
open-source server-side scripting language
Back
HTTP POST method,
where does it submit all form data?
we use the $_POST associative array to?
What does the array key correspond to?
Front
HTTP header
access data
name attribute value
Back
var_dump($_POST);exit();
Front
Back
every line must end with what?
Front
; (semicolon)
Back
Why do we need to close the DB connection? and How do you code it?
Front
DB servers have a limit on max number of simultaneous connections so it's best practice to code:
$mysqli->close();
Back
When should you use the GET METHOD:
Front
handling non-sensitive data
sending small amount of data
users can bookmark data
usually used to retrieve data
Back
what does php stand for?
Front
hypertext preprocessor
Back
In order to establish db connection what do you need to create? code it.
Front
create MySQL object
$mysqli = new mysqli($host, $user, $pass, $db);
check for connection errors:
if ( $mysqli->connect_erno ) {
echo "mysql connection error:" . $mysqli->connect_error;
exit();
}
Back
How do you submit SQL Query? code it
Front
create a SQL statement:
$sql = "SELECT * FROM table;";
submit SQL query to DB and save results into a variable:
$results = $mysqli->query($sql);
check for any errors:
if( !$results ) {
echo "SQL Error:" . $mysqli->error;
exit();
}