web4.cs.universityofgalway.ie

Home
This php code connects to a remote mysql database server on mysql1 and retrieves records
MySQL Server: mysql1.cs.universityofgalway.ie via TCP/IP
Database: mydb2962
Company nameContact NameTitleCity
Alfreds Futterkiste JnrMaria AndersSales RepresentativeBerlin
Ana Trujillo Emparedados y heladosAna TrujilloOwnerMéxico D.F.
Antonio Moreno TaqueríaAntonio MorenoOwnerMéxico D.F.
Around the HornThomas HardySales RepresentativeLondon
Berglunds snabbköpChristina BerglundOrder AdministratorLuleå
Blauer See DelikatessenHanna MoosSales RepresentativeMannheim
Blondesddsl père et filsFrédérique CiteauxMarketing ManagerStrasbourg
Bólido Comidas preparadasMartín SommerOwnerMadrid
Bon app'Laurence LebihanOwnerMarseille
Bottom-Dollar MarketsElizabeth LincolnAccounting ManagerTsawassen

The PHP Code for the above is shown below


<?php include 'head.html'?>
<table width="90%">
        <tr>
          <td>
<h2><?php print $_SERVER["HTTP_HOST"]; ?></h2>
<a href="/">Home</a><br />
<?php

$db_server 
"mysql1.it.nuigalway.ie";
$db_name "mydb2962";
$db_user "";
$db_pass "";


print(
"This php code connects to a remote mysql database server on mysql1 and retrieves records<br />");

$mysqli = new mysqli($db_server,$db_user,$db_pass,$db_name);
if (
$mysqli->connect_errno) {
    echo 
"Failed to connect to MySQL: (" $mysqli->connect_errno ") " $mysqli->connect_error;
}


print(
"MySQL Server: <b>" $mysqli->host_info ."</b><br/>");
print(
"Database: <b>".$db_name."</b><br/>");

// Create the SQL statement. Here we specify the columns we want from the customers table, and limit the number of rows returned to 10
$sql "SELECT CompanyName,ContactName,ContactTitle,City FROM Customers limit 10";
// Run the SQL statement on the MySQL connection
$result $mysqli->query($sql);

// If there are records that match the query then proceed further....
if ($result->num_rows 0) {
    
printf("<table border=1><tr><td>Company name</td><td>Contact Name</td><td>Title</td><td>City</td></tr>");
    
// while there is a record to fetch, display its contents in a table
    
while ($myrow $result->fetch_assoc()) {
        
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>"$myrow["CompanyName"], $myrow["ContactName"], $myrow["ContactTitle"], $myrow["City"]);
    }
    
printf("</table>");
}

print 
"</center>";

print 
"<h3>The PHP Code for the above is shown below</h3><hr>";

highlight_file('SRCdbtest_remote.php');
?>

          </td></tr></table>
<?php include 'foot.html'?>