I've been away from programming for a few years and am working through the examples in the book PHP and MySQL Web Development to get back up to speed. I've discovered a few things that are done differently from what the book says, and when I make those changes, things work. (Imagine that!) But, I have not found what works to access a MySQL database.
I'm trying to do these exercises on both my XP machine and by Linux machine.
I installed both MySQL and PHP with the msi installers on the XP machine, and I was able to run the MySQL monitor and create and populate a database. I can examine that database with the MySQL monitor, but I can't access it with PHP. Here's the code:
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
$searchterm = htmlspecialchars($_POST['searchterm']);
$searchtype = htmlspecialchars($_POST['searchtype']);
$host = "localhost";
$user = "user";
$password = "pass";
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
echo "searchtype after addslashes = $searchtype <br>";
echo "searchterm after addslashes = $searchterm <br>";
@ $db = mysql_pconnect($host, $user, $password);
echo "db = $db <br>";
echo "This is a line of text.";
(snip)
When this page is run, I get the text between the <h1> tags, and the echo-ings of $searchtype and $searchterm, but I don't get anything after that. If I comment out the mysql_pconnect line the next two echos work. I conclude from that that there is a problem with the way I'm trying to connect. The PHP manual didn't help -- it looks to me like I'm using mysql_pconnect correctly.
Did I miss something? Any recommendations on how to proceed?
On My Linux machine I haven't gotten that far. I used the mysql monitor to create the user bookorama, and the empty database books, but I am unable to start the mysql monitor with the user bookorama. When I look at that user with MySQL Adminstrator I see that the number of characters in the password doesn't match the number in the password I used. I try to change the password with MySQL Administrator and see it appear to work, but I still can't start the mysql monitor as user bookorama, and when I start up MySQL Administrator again, the character count has reverted to what it was before. This is more of a MySQL problem than a PHP one, but I'm hoping someone here will have some ideas for me. I posted the problem over at the MySQL forum, but haven't had any responses.
Thanks.