-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path02.error_reporting_1.php
50 lines (43 loc) · 1.25 KB
/
02.error_reporting_1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Wines</title>
</head>
<body><pre>
<?php
function showerror() {
die("Error " . mysql_errno() . " : " . mysql_error());
}
require_once('db.php');
// (1) Open the database connection
if (!($connection = @mysql_connect(DB_HOST, DB_USER, DB_PW))) {
die("Could not connect");
}
// And select the winestore database
// NOTE : 'winestore' is deliberately misspelt to cause an error
if (!(@ mysql_select_db("winestor", $connection))) {
showerror();
}
// (2) Run the query on the winestore through the connection
if (!($result = @ mysql_query ("SELECT * FROM wine", $connection))) {
showerror();
}
// (3) While there are still rows in the result set,
// fetch the current row into the array $row
while ($row = @ mysql_fetch_array($result, MYSQL_NUM))
{
// Print out each element in $row, that is, print the values of
// the attributes
foreach ($row as $attribute) {
print "{$attribute} ";
}
// Print a carriage return to neaten the output
print "\n";
}
?>
</pre>
</body>
</html>