Simple MySQL script is not working
Posted on
16th Feb 2014 07:03 pm by
admin
Hey guys,
Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly book that addresses both topics and has the platypus on the cover.
At any rate, I tried typing in chapter 6 exercise 1 and the script did not work. I then downloaded the example code from the books website and found out what I typed was identical and actually tried the downloaded script and had THAT not work.
Other PHP scripts are working, so I know it's not the system. For instance phpinfo.php does it's thing, as do my other scripts so far.
Here is the code from the downloaded example:
Code: [Select]<!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
// (1) Open the database connection
$connection = mysql_connect("localhost","fred","shhh");
// (2) Select the winestore database
mysql_select_db("winestore", $connection);
// (3) Run the query on the winestore through the connection
$result = mysql_query ("SELECT * FROM
wine", $connection);
// (4) 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))
{
// (5) 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>
I am running a Mac OS X 10.6 (Snow Leopard) system and have put the script in the same place that my other PHP scripts are working : Mac HD -> Library -> WebServer -> Documents
This simple script is meant to access a MySQL db and print it's contents in a web browser. Obviously the db login here is fake. But in the 'real' script I have tried a user that should have rights and even tried it with root which I KNOW has rights. I am able to access the db from the command line interpreter using both the user and with root. The script and the browser are running locally on my machine and being served by apache (which has been restarted both with apachectl and with the GUI tools).
Thanks!
No comments posted yet
Your Answer:
Login to answer
340
31
Other forums
Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then
rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded
matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi
Functions Not Loading Into Div
I had some help doing some of this but what I'm trying to do is get my functions to retrieve its val
PHP / MySQL Associative Multidimensional Array:
Hello.
I have data in a MySQL Table that adheres to the below: (note, no index, could add if
do while conditions
i want to display 6 images in a 2x3 table
now what would be the correct logic to
count that th
About imagecopyresampled()
Hello,
I am looking to use this function to resize parts of an image to a fixed thumbnail siz
help with multi-update
Now sure how to ask this really....
10g database if that matters.
I have a customer
Simultaneous select/update/insert
Hi
How would I need to go about when 2 users update a single row simultaneous? And how would
Web Application Recipe
Hi Guys!
I am working with the Web Application recipes. I am currently working on the sen