mysql_connect isn't working right

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
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

mysql_connect isn't working right

Post by snowrhythm »

I'm testing a script on my localhost and I'm having some trouble getting a connection with mysql_connect. The
script is this...

Code: Select all

$connect = mysql_connect("localhost", "root", "");

if(!$connect){
	die('<h3>im sorry, i could not connect to your databases: </h3><br />'  .mysql_error()); 
}
and just so nobody will ask....the root has no password. Anybody have anyideas? The folder that this script is
in is about 3 subfolders into the root directory. Thanks for any help!
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

a) Are you getting any errors? Show us the page output.

b) Are you sure the mysql service is running.

c) Its a really bad idea to have the root password as '' on a production machine
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

I don't get any errors on the page...all it does is print out my die() message and then prints the rest of the script.
I'm using wamp for my server/database tools and i'm pretty sure mysql is running. WAMP tells me it's running anyway.
I have the root password set to '' because there's nothing of real importance in my personal mysql database here at work, I only
use it for testing...any sensitive data is kept on our other servers.

do you think there's something wrong with my php configuration?
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Try this:

Code: Select all

mysql_connect('localhost', 'root', '') OR DIE ('Connection Failed:' . mysql_error());
If you are using WAMP, PHP should be configured to work with MySQL
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

Post by angelena »

How bout this?

Code: Select all

$link = mysql_connect('mysql_hostserver', 'mysql_username', 'mysql_password')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('database_name') or die('Could not select database');
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

hey guys, got it fixed! thanks for you help...it actually turned out to be a pretty easy solution, got it fixed
last week and I don't remember exactly what it was, but something really small.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Don't forget to set a password for your database. Having no password is very risky.
Post Reply