CS2020:   Web Science, Sytems and Design

PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
PHP test

<?php
print "hi_start";^M
$hostname_MySQLServer ="mcsdb1.sci.csueastbay.edu:3306";^M
//$hostname="mcsdb1.sci.csueastbay.edu" ; //without port^M
$database_MySQLServer = "3306";^M
$username_MySQLServer = "grewe";^M
$password_MySQLServer = "lynnegrewe";^M
print " before connect ";^M
$MySQLServer = mysql_connect($hostname_MySQLServer, $username_MySQLServer, $pas
sword_MySQLServer);
// or trigger_error(mysql_error(),E_USER_ERROR);


print "Called connect";

//mysql_select_db("grewe_test",$MySQLServer); //login_database

if (!($MySQLServer === false)) {
if (mysql_select_db("test", $MySQLServer) === false) {
echo('Could not select database: ' . mysql_error());
continue;
}
}
$query = 'SELECT * FROM Customer';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

print "hi";
?>

</body>
</html>

 

Try It

 

Output in Text:

/opt/csw/php53/bin/php *.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
PHP test

hi_start before connect Called connect<table>
<tr>
<td>123</td>
<td>Grewe</td>
<td>Lynne</td>
<td>123 3rd Ave</td>
<td>Hayward</td>
<td>CA</td>
<td>99999</td>
</tr>
<tr>
<td>399</td>
<td>Smith</td>
<td>Jack</td>
<td>33 A Street</td>
<td>San Francisco</td>
<td>CA</td>
<td>99999</td>
</tr>
</table>
hi
</body>
</html>

 

 

© Lynne Grewe