Hi everyone! :)

I'm just starting out with php and mysql, and encountered the following problem:

I have installed:

Apache 2.2.8-1
PHP 5.2.5-7
MySQL 5.0.51-3

on an Arch-Linux system.
Apache and PHP are working: I tested that.

I can log in to mysql from the commandline; I made a small database for a test.
When I try to connect to this database from a webpage with this php-code:

<?php
require_once('db_login.php');
// connect
$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
        die ("Kan geen verbinding krijgen met de database: <br />".mysql_error());
};
// select database
$db_select=mysql_select($db_database);
if (!$db_select){
        die ("Database niet gevonden: <br />".mysql_error());
};
mysql_close($connection);
echo "succes !";
?>

file db_login.php:

<?php
$db_host='127.0.0.1';
$db_database='bandjes';
$db_username='ko';
$db_password='Kobus';
?>

I get this error:

Kan geen verbinding krijgen met de database:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0

So there's an error on the mysql_connect() function, but I don't understand what the error is...

Anyone any idea?? :?:

erm...

code seems ok

i noticed the capital K on Kobus (your password)

could you recheck all your details and then reply, oh and instead of
127.0.0.1 (as your $host)
try
localhost

any help?

also i would suggest installing a program called
wampserver

its
-apache
-php
-mysql
-phpMyadmin (interface for mysql instead of using the command prompt)

i use it
easy 2 install
has everything u need
and easily to controll

hope this also helps :D

erm...

code seems ok

i noticed the capital K on Kobus (your password)

could you recheck all your details and then reply, oh and instead of
127.0.0.1 (as your $host)
try
localhost

any help?

Designer_101,

Thanks for your reply.

Password worked logging in from the commandline, so that seems to be O.K.
I already tried localhost instead of I.P., in fact that was the first version. Somehow the system doesn't recognise localhost, although I have "127.0.0.1 localhost" in /etc/hosts.
If I replace 127.0.0.1 by localhost, I get an empty page...

This article has been dead for over six months. Start a new discussion instead.