Page 1 of 1

mysql_connect doesn't work though phpmyadmin works

PostPosted: 11. June 2004 10:59
by covenant
Hey there,

i'm a newby in xampp and mysql aswell. i installed xampp on my xp pro machine. as far as i could figure out up to now everything works perfectly. for instance: i can create databases and tables in phpmyadmin; i can enter data into them in phpmyadmin and i can search the database in the same surface.
the readme-file of xampp says that
With the preset values, you'll have to use the following syntax: mysql_connect("localhost","root","");

but when i use this action in php my page can't connect to the database. it doesn't return an error neither.
in my php-file i programmed the following to get at least any result:
function printError($errorMesg)
{
printf("<br> %s <br>\n", $errorMesg);
}
if (!($link = mysql_connect("localhost","root","")));
{
printError(sprintf("error connecting to host %s, by user %s", $host, $user)); exit();
}

when running the script, it answers;
error connecting to host localhost, by user root


i didn't change anything in the configuration of any of the programs in xampp.

the truth is out there, they say, thus i hope it will find its way here :wink:

PostPosted: 11. June 2004 11:30
by Wiedmann
Code: Select all
function printError($errorMesg)
{
printf("<br> %s <br>\n", $errorMesg);
}
if (!($link = mysql_connect("localhost","root","")));
{
printError(sprintf("error connecting to host %s, by user %s", $host, $user)); exit();
}



Try this code to make connection to the database:
Code: Select all
$link = mysql_connect('localhost', 'root', '')
   or die ('error connecting to host: '.mysql_error());

What happens?

PostPosted: 13. June 2004 23:35
by free69
Code: Select all
function printError($errorMesg)
{
printf("<br> %s <br>\n", $errorMesg);
}
if (!($link = mysql_connect("localhost","root","")));
{
printError(sprintf("error connecting to host %s, by user %s", $host, $user)); exit();
}


I think you can connect if you put password like this

if (!($link = mysql_connect("localhost","root","password")));

PostPosted: 14. June 2004 20:51
by micha78347
if your user (eg root) haves no password set then you may use:

if(!$link=mysql_connect('localhost','root')) print "err connecting";

I have the same problem

PostPosted: 23. June 2004 11:08
by dekatvandeburen
I have the same problem on my winXP Pro box. PhpMyAdmin works fine, but when i try to connect in my own php scripts, i get nothing. I tried the various codes posted in this topic, but MySql does not return an error, it just doesn't return anything :(

Anyone got an idea how we can fix this? Maybe something in the MySql config or something?