Log in

View Full Version : Installing PHP



bob4242
08-06-2009, 10:04 AM
Hi guys,

I am somewhat competent with HTML, CSS and Javascript, now I'm trying to start using PHP. I've downloaded and installed Apache, PHP and MySQL and they kind of work. I can use MySQL on its own fine, and PHP on its own fine (I can run phpinfo, echo Hello World etc. and can visit pages on localhost). However I can't get my PHP script to work using MySQL. I copied out *exactly* a script from O'Reilly's PHP and get the following errors printed out:

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\AppServ\www\mysql2.php on line 14

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\AppServ\www\mysql2.php on line 14
2002
Warning: mysql_select_db() [function.mysql-select-db]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\AppServ\www\mysql2.php on line 21

Warning: mysql_select_db() [function.mysql-select-db]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\AppServ\www\mysql2.php on line 21

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\AppServ\www\mysql2.php on line 21

Fatal error: Maximum execution time of 60 seconds exceeded in C:\AppServ\www\mysql2.php on line 21

Here is the script, the password, host etc. is definitely correct, I've double checked in MySQL itself.


<html>
<head>
<basefont face="Arial">
</head>
<body>

<?php
$host = "localhost";
$user = "root";
$pass = "elephant";
$db = "favourite_foods";

// open connection
$connection = mysql_connect($host, $user, $pass); /*THIS IS LINE 14!!!!*/

if(mysql_error()) {
echo mysql_errno();
}

// select database
mysql_select_db($db) or die ("Unable to select database!"); /*THIS IS LINE 21!!!!*/


// create query
$query = "SELECT * FROM favourite_food";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned
if (mysql_num_rows($result)>0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>" . $row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);

?>

</body>
</html>

Is there anything obvious I'm doing wrong? Any help would be very much appreciated. Thanks, Bob

Schmoopy
08-06-2009, 11:46 AM
Definitely nothing wrong with the way the script connects, normally if the user / password is incorrect the mysql error will say "Access denied for user $user"

So it's probably to do with how you've placed the files, have you googled your error message for more information?

rm_dynamicdrive
08-07-2009, 07:11 AM
you need to copy this 2 files in your c:\windows\system32

libmysql.dll and libeay32.dll coming from your php dll files.

sysout
08-08-2009, 09:58 AM
just install xampp, it's more easier.