• Why is my Mysql connection not working?
    15 replies, posted
Here's a link to the Php script which controls it: [url]http://elliottstutorials.com/elliottstutorials/php.php[/url] here's the script: <html><body> <title>Password!</title> <center><h4>Admin page</h4></center> <?php mysql_connect("*******", "******", "*******") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> I have put axterix in to hide the logon information. </body></html> What's happening? The server uses MYSQL 4.1
try mysql_connect('blah','blah,'blah') with ' not "
[QUOTE=Grayron;16021925]try mysql_connect('blah','blah,'blah') with ' not "[/QUOTE] It makes no difference. Give me a sec and i'll check your code. If you censor it, it doesn't help. Add dummy login info. Try this: [code] <? $username = "cake"; $password = "rules"; $hostname = "locahost"; // This is almost always localhost. $db = mysql_connect( $hostname, $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?> [/code]
[QUOTE=Blynx6;16022192]It makes no difference. Give me a sec and i'll check your code. If you censor it, it doesn't help. Add dummy login info. Try this: [code] <? $username = "cake"; $password = "rules"; $hostname = "locahost"; // This is almost always localhost. $db = mysql_connect( $localhost, $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?> [/code][/QUOTE] I tried this and it did not work. Could I be because I'm using mysql 4.1?
<? $username = "cake"; $password = "rules"; [b]$hostname[/b] = "locahost"; // This is almost always localhost. $db = mysql_connect( [b]$localhost[/b], $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?> That's probably why.
[QUOTE=n00bmuffin;16022523]<? $username = "cake"; $password = "rules"; [b]$hostname[/b] = "locahost"; // This is almost always localhost. $db = mysql_connect( [b]$localhost[/b], $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?> That's probably why.[/QUOTE] I did fix that. but still nothing.
Are you hosting this somewhere else or is it on your computer?
[QUOTE=n00bmuffin;16022523]<? $username = "cake"; $password = "rules"; [b]$hostname[/b] = "locahost"; // This is almost always localhost. $db = mysql_connect( [b]$localhost[/b], $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?> That's probably why.[/QUOTE] Oops. Typo, haha. Thanks. [editline]06:58AM[/editline] [QUOTE=n00bmuffin;16022577]Are you hosting this somewhere else or is it on your computer?[/QUOTE] This. If you aren't hosting on the same server as the mysql. You need the mysql hostname.
[QUOTE=Blynx6;16022590]Oops. Typo, haha. Thanks. [editline]06:58AM[/editline] This. If you aren't hosting on the same server as the mysql. You need the mysql hostname.[/QUOTE] It's on the server.
Sometimes you still need the mySQL hostname, no?
[QUOTE=Klownox;16022740]Sometimes you still need the mySQL hostname, no?[/QUOTE] No.
[code]<?php $username = "cake"; $password = "rules"; $hostname = "loca[highlight]l[/highlight]host"; // This is almost always localhost. $db = mysql_connect( $hostname, $username, $password ); if(!$db) { echo "Failed to connect: ". mysql_error(); } else { echo "Connected to mysql!"; } ?>[/code] Fixed.
He can't have been the only one to notice that...
Holy shit..That's what happens when you write code about 1-2 minutes after you just wake up.
You mention you have a MySQL 4.1 server. The socket is pointing to a 5.0 daemon.
Get like appserv or xxamp which has appache/mysql/php :) It will help alot
Sorry, you need to Log In to post a reply to this thread.