I can't connect to a database:

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
greenAlien
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2003 10:08 pm

I can't connect to a database:

Post 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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Code: Select all

mysql_connect("HOSTNAME",$user, $pwd);
greenAlien
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2003 10:08 pm

Post by greenAlien »

mysql_connect() works fine!

mysql_select_db($db) Does not.
Bongulim
Forum Newbie
Posts: 21
Joined: Thu Aug 07, 2003 12:50 pm

Post 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)
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Okay, sorry, I forgot that you can specify default values for the mysql_connect function in your php.ini file.
greenAlien
Forum Newbie
Posts: 8
Joined: Sun Aug 17, 2003 10:08 pm

Post 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.
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post 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?
Bongulim
Forum Newbie
Posts: 21
Joined: Thu Aug 07, 2003 12:50 pm

Post by Bongulim »

I'm sorry for that one... :roll:
Post Reply