Page 1 of 1
mysql_connect isn't working right
Posted: Thu Oct 19, 2006 1:29 pm
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!
Posted: Thu Oct 19, 2006 2:00 pm
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
Posted: Thu Oct 19, 2006 2:14 pm
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?
Posted: Thu Oct 19, 2006 5:17 pm
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
Posted: Thu Oct 19, 2006 8:36 pm
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');
Posted: Mon Oct 23, 2006 10:59 am
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.
Posted: Mon Oct 23, 2006 11:21 am
by RobertGonzalez
Don't forget to set a password for your database. Having no password is very risky.