Page 1 of 1
Connection Problems
Posted: Mon Mar 09, 2009 9:15 pm
by WideKurt
I can't connect to my MySQL database from PHP. Following is the code:
Code: Select all
<?php
$PhpUser = "PhpUser";
$PhpHost = "localhost";
$PhpPass = "phppass";
$link = mysql_connect($PhpHost, $PhpUser, $PhpPass);
if (!$link) {
die("Could not connect: " . mysql_error());
}
echo 'Connected successfully';
?>
mysql_error returns nothing. When linking to the page that contains this script, I get an HTTP 500 error. Seems almost like a script error but nothing obvious to me.
Re: Connection Problems
Posted: Mon Mar 09, 2009 10:01 pm
by Benjamin
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Re: Connection Problems
Posted: Mon Mar 09, 2009 10:45 pm
by califdon
Since you received an HTTP 500 error, there is clearly something wrong with the server configuration. Is this your own server or a hosting service? If it is a hosting service, you need to contact their tech support. If it is your own server, something is not configured correctly, either in the PHP or the MySQL configuration files.
Re: Connection Problems
Posted: Wed Mar 11, 2009 9:15 am
by WideKurt
It's Apache running on my own computer. Odd thing is, after I get the 500 error, if I hit refresh, I get the page, but still cannot connect to the database. No error either. What I get is the "Unable to Connect" from the echo statement, but nothing from the error portion of the same statement.
I've noticed if I have a syntax error, sometimes I get the HTTP 500 error in other cases.