"Tables and Functions" Please respond to the following:

Computer Science
Tutor: None Selected Time limit: 1 Day

Describe three differences between the mysql_fetch_row() function and the mysql_fetch_assoc() function. Provide an example of a situation or scenario that demonstrates the use of these functions with database designs.

Feb 28th, 2015

The mysql_fetch_row() function fetches one row from a result-set and returns it as an enumerated array.

<?php
$con=mysql_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysql_connect_errno())
 {
  echo "Failed to connect to MySQL: " . mysql_connect_error();
 }

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";

if ($result=mysql_query($con,$sql))
  {
  // Fetch one and one row
  while ($row=mysql_fetch_row($result))
  {
  printf ("%s (%s)\n",$row[0],$row[1]);
  }
  // Free result set
  mysql_free_result($result);
}

mysql_close($con);
?>

the function mysql_fetch_assoc() puts all the results into an associative array that we can loop through, If there are more than zero rows returned, 

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);


$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
  echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
  }
} else {
  echo "0 results";
}
$conn->close();
?>

Mar 1st, 2015

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Feb 28th, 2015
...
Feb 28th, 2015
Feb 19th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer