Back to the basics

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Back to the basics

Post by tazdog »

I'm trying to get some connection issues resolved.
(yes I'm learning how to do this)

I have tried 3 different ways, but when I upload the code to my server, and display the page I get nothing in return.
So maybe I'm doing something wrong..

IF I read the code right I should get a die msg if I change the user name or passwd right.?
Well all I get is a blank screen when trying to goto the page.

Now if I do change the user name or passwd then I do get a die msg now, but is there a way to display a msg if I have connected..?

Here is the code I'm trying to use now:
<?php
$host = "MY IP";
$user = "MY USR NAME";
$pswd = "MY PASSWD";
$dbname = "MY DB";

$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db("$dbname")
or die(MySQL_Error());
?>

thanks for your help..
Scott
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Simply do it like this

Code: Select all

<?php
if (mysql_connect($host, $user, $pswd)) {
   echo 'connected';
} else {
  echo 'some error';
}

?>
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Post by tazdog »

Thank you very much

Scott
Post Reply