Page 1 of 1

I can't connect to a database:

Posted: Tue Aug 19, 2003 1:41 pm
by greenAlien
I can't connect to a database:

My config = Windows, PHP Version 4.3.2, MySQL 3.23.54-nt

This works...

<?php
$user = "";
$pwd = "";
$db = "php24";
$link = mysql_connect();
if (! $link)
die ("Could not connect to MySQL");
print "Successfully connected to server<p>"
?>

This does not...

<?php
$user = "";
$pwd = "";
$db = "php24";
$link = mysql_connect();
if (! $link)
die ("Could not connect to MySQL");
print "Successfully connected to server<p>"

mysql_select_db($db)
or die ("Could not select $db: ".mysql_error() );
print "Successfully selected database \"$db\"<p>";
mysql_close($link);
?>

I have tried multipul databases and even tried creating a new one (php24)

Any suggestions?

Thanks

Posted: Tue Aug 19, 2003 2:29 pm
by nigma

Code: Select all

mysql_connect("HOSTNAME",$user, $pwd);

Posted: Tue Aug 19, 2003 6:46 pm
by greenAlien
mysql_connect() works fine!

mysql_select_db($db) Does not.

Posted: Tue Aug 19, 2003 7:35 pm
by Bongulim
add ; where missing.
you know, it could help alot if you given out the error message (or whatever happend if you didn't get one)

Posted: Tue Aug 19, 2003 10:52 pm
by nigma
Okay, sorry, I forgot that you can specify default values for the mysql_connect function in your php.ini file.

Posted: Tue Aug 19, 2003 11:56 pm
by greenAlien
Bong,

No error message. I get a blank browser. If there was an error message, I probably would have mentioned it.

In the spirit of mentioning errors... check your grammar, and hold the sarcasm.

Posted: Wed Aug 20, 2003 9:33 am
by trollll
Just as a quick note: lots and lots of people post things without giving any info. Things like pasting three pages of code and just saying,"Why doesn't this work?" to give you an extreme example. Though I don't like sarcasm towards people who probably feel quite annoyed by a problem to begin with, bong did try to help.

Anyway, did adding the ";" to

Code: Select all

print "Successfully connected to server<p>"
allow it to print anything out?

Posted: Wed Aug 20, 2003 11:20 am
by Bongulim
I'm sorry for that one... :roll: