turbo_h4 Posted January 15, 2008 Share Posted January 15, 2008 i have the very basic code and i can't seem to connect to my sql database. here is my code, it's just testing so i included the password. $hostname="xxxx"; $mysql_login="xxxx"; $mysql_password="xxxx"; $database="xxxx"; if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){ die("Can't connect to database server."); }else{ echo 'connected'; // select a database if (!(mysql_select_db("$database",$db))){ die("Can't connect to database."); } } even if i change the server to something irrelevant i get the same blank page. doesn't show errors.. Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/ Share on other sites More sharing options...
papaface Posted January 15, 2008 Share Posted January 15, 2008 Instead or defining a message for your die's use mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440440 Share on other sites More sharing options...
dooper3 Posted January 16, 2008 Share Posted January 16, 2008 remove the quote marks from either side of $database when you select the database. OR Don't put the name of the database into a variable at all and keep the quote marks when connecting to the database. Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440448 Share on other sites More sharing options...
PFMaBiSmAd Posted January 16, 2008 Share Posted January 16, 2008 A blank php page is usually due to a fatal parse error or a fatal runtime error. Check your web server log for errors. Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440456 Share on other sites More sharing options...
turbo_h4 Posted January 16, 2008 Author Share Posted January 16, 2008 thanks for the replies. this is what i have now, still doesn't work.. <?php /*--------- DATABASE CONNECTION INFO---------*/ $hostname="xxxx"; $mysql_login="xxxx"; $mysql_password="xxxx"; $database="xxxx"; if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){ mysql_error(); }else{ echo 'connected'; // select a database if (!(mysql_select_db($database,$db))){ mysql_error(); } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440507 Share on other sites More sharing options...
teng84 Posted January 16, 2008 Share Posted January 16, 2008 $hostname="*****"; $mysql_login="*****"; $mysql_password="*****"; $database="71874_new"; if (!mysql_pconnect($hostname, $mysql_login , $mysql_password)){ mysql_error(); }else{ echo 'connected'; // select a database if (!(mysql_select_db($database,$db))){ mysql_error(); } } try.. is that your real connection info? you should not display that Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440522 Share on other sites More sharing options...
awpti Posted January 16, 2008 Share Posted January 16, 2008 <?php $hostname="xxxxx"; $mysql_login="xxxx"; $mysql_password="xxxx"; $database="xxxx"; $db = mysql_connect($hostname, $mysql_login , $mysql_password) or die(mysql_error()); //mysql_pconnect is BAD. if (!$db) { //Oh noes! It be brokeded! } else { echo 'connected'; // select a database mysql_select_db($db) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440523 Share on other sites More sharing options...
thomashw Posted January 16, 2008 Share Posted January 16, 2008 Take your login info off! (If it's real.) Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440530 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 If it's like my DBs, you can't get to it unless you go through a CPanel anyways. try.. is that your real connection info? you should not display that Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440531 Share on other sites More sharing options...
awpti Posted January 16, 2008 Share Posted January 16, 2008 Yeah, most are setup to only listen on the local loopback device. I could give you my DB user and pass.. you'll never touch it no matter how hard you try - just because it only listens on 127.0.0.1 Quote Link to comment https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/#findComment-440555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.