Section 1

Preview this deck

The mysqli_fetch_array() function...

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

7 years ago

Date created

Mar 1, 2020

Cards (38)

Section 1

(38 cards)

The mysqli_fetch_array() function...

Front

retrieves a row of data from the results of a database query

Back

Describe the process of querying a database of how you should use them in your php program. (4)

Front

Step 1 - mysqli_connect(), Step 2 - mysqli_query(), Step 3 - mysqli_fetch_array(), Step 4 - iterate over result $row with foreach or while loop, or otherwise process the data returned.

Back

mysqli_connect()

Front

This opens a connection between the PHP script and the MySQL server so they can communicate

Back

Suppose you have an HTML form that looks like this: <form action="somescript.php" method="POST"> <input type="text" name="firstname"> <input type="submit" name="submit" value="Submit Form"> </form> What is the correct code that should be included in "somescript.php" that will allow us to capture/access the form value typed by our user?

Front

$firstname = $_POST["firstname"];

Back

Suppose you are debugging the following lines of php code. You expect the program to act one way, but it is doing strange things. On which line is the first major syntax problem with this code located? Type the line number of the first error in the answer box. 1 <?php 2 $fiddle = "pinkie"; 3 $waffle = "tickle"; 4 if (($waffle == "pickle") && ($fiddle == $waffle)) 5 { 6 print fiddle; 7 } 8 else ($fiddle . $waffle == "pickle") 9 { 10 print "bar"; 11 } 12 ?>

Front

6 There is a missing $ on line 6. Yes, line 8 is a horrific tragedy (else doesn't get to take a condition), but the question asks which error is FIRST.

Back

To read data out of a database, we use the SQL command ___.

Front

SELECT

Back

After creating a new database in a MySQL terminal, you must issue this command before you can do anything with the database

Front

USE

Back

Given the following php code, what is the number of cats that is printed at the end? function breedSomeCats($numberOfCats) { $numberOfCats = ($numberOfCats (2 $numberOfCats)) - $numberOfCats; } $numberOfCats = 2; breedSomeCats($numberOfCats); print "The number of cats is: $numberOfCats"; exit;

Front

2 The variable is "passed by value" in php, which means the value "2" is passed to the function. Unfortunately, the result of the equation inside the function is never carried back to the original variable. Thus, the result remains "2". If you wish to allow the value to change inside the function you must either "pass by reference" or you must have your function return a value and use that.

Back

A MySQL database is divided into these

Front

Tables

Back

mysqli_select_db()

Front

This option PHP function tells the database server which database to use

Back

Issuing an SQL query from PHP code involves...

Front

assembling the query in a string and then executing it with a call to mysqli_query()

Back

What will be the output of the following PHP code? $foo = 2; do_some_math($foo); function do_some_math($foo) { $foo = $foo * 2; print ($foo); }

Front

4

Back

What will be the output when the following PHP code is run? for ($i=0; $i<9; $i++) { echo $i; }

Front

012345678

Back

Using the keyword include, you can tell PHP to load a particular file. If the file is not found, no error is generated. However, if you wish to stop execution of your program if that file is not found, use the keyword ____ instead. (For example, to load a file full of passwords and connection parameters for the database, we would use the ____ keyword.)

Front

require

Back

query

Front

This SQL code the PHP script passes to the MySQL server

Back

mysqli_query()

Front

This PHP function sends a query to the MySQL server

Back

Given the following PHP code, write the value of the element $foo[3] $foo = array("apple","plum","orange","grape","kiwi","banana","nectarine");

Front

"grape"

Back

The die() function:

Front

exits the script and returns feedback if your connection fails

Back

Database connections need a ________, _________, _________, and __________

Front

Database connections need a LOCATION, a USERNAME, a PASSWORD, and a DATABASE NAME

Back

MySQL database server

Front

This is another name for the software that runs MySQL and all the databases and tables it contains

Back

A persistent, highly organized, data structure that is typically stored in a file on a hard drive.

Front

Database

Back

True or false: assuming $foo = NULL, the following two code snippets are logically equivalent (i.e. they will both return FALSE). if ($foo != NULL) if (isset($foo))

Front

TRUE

Back

POSt

Front

The HTML form uses this request method to send the data in the form to a PHP script

Back

What will be the resulting printed text from the following php program? $foo = 3; while ($foo < 10) { $foo++; } if (($foo <=3) || ($foo >= 10)) { print "success!"; } else { print "error!"; }

Front

"success" The program prints "success!" when run. The value of $foo starts at "3" and the while loop bring it up to 10. The "if" condition fires because EITHER $foo was equal or less than 3 (false) OR $foo was equal or greater than 10 (true).

Back

Assuming you have the following php code to store the records returned from a database query, what is the correct way to access an individual value from that query? while ($row = mysqli_fetch_array($result)) { // what goes here? }

Front

print "<br />Some value: " . $row["somecolumn"] . "<br />";

Back

The process of connecting to a MySQL server in php has at least these six steps. What are they in order?

Front

1. Connect to the database server, located on a particular host, using an authenticated username and password 2. Choose which database on that server to use 3. Send your query 4. Get a result set 5. Process the results 6. Close the connection to the server

Back

<form ______="http://myserver.com/somescript.php" ______="POST">

Front

action, method

Back

INSERT statement template

Front

INSERT INTO table_name (column_name1, column_name2, ...) VALUES ('value1', 'value2', ...)

Back

web server

Front

This runs PHP scripts and returns HTML pages to browsers, often communicating with a database along the way

Back

if (($foo == "bar") AND ($foo == "flarg")) { echo "baz"; }

Front

Both halves of the conditional OR statement will execute, but they will only ever happen in the order shown.

Back

$query = "SELECT columnA, columnB FROM table WHERE columnC="foo"";

Front

$query = "SELECT columnA, columnB FROM table WHERE columnC=\"foo\""; OR $query = "SELECT columnA, columnB FROM table WHERE columnC='foo'";

Back

True or false: Once you have opened a MySQL database connection in PHP, you can run multiple queries before closing the connection.

Front

TRUE

Back

Consider a block of code written with an if/else construction in PHP (assume no elseif). What must happen? if (something) { //A happens here } else { //B happens here }

Front

Either A or B must happen

Back

mysqli_close()

Front

This PHP function closes a connection to the MySQL server

Back

When dynamic functionality is added to a web site via PHP and MySQL, it becomes an ....

Front

Application

Back

Variables with special names that begin with words like $_POST or $_GET or $_SERVER are known as ___. (one compound word)

Front

superglobals

Back

Submit button

Front

This HTML element is used by visitors to the site when they finish filling out the form

Back

What are superglobals recognized by PHP?

Front

$_POST $_SESSION $_GET $_SERVER

Back