Member Avatar for Kobussie

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

Member Avatar for Kobussie

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.