Phobios Posted September 3, 2009 Share Posted September 3, 2009 When I try to connect from my php-script to my mysql server on localhost it will not work. This is the test code I am using while trying to get it to work: <?php $user = "user"; $password = "password"; $host = "localhost"; $db = "db"; echo first; $conn = mysql_connect($host,$user,$password) or die("Problems connecting: " . mysql_error()); echo second; $db = mysql_select_db($conn); mysql_close($conn); ?> After the mysql_connect call nothing will be displayed and I get no error message whatsoever. I have set all the right privileges in the mysql database. I have looked through the php.ini file and found no fault in there. I have googled alot on the subject, but I haven't found anything of help yet. On my real page, which I will use it on, the css on the page gets screwed up as well. I am using fedora core 11. I hope someone out there can help me out. Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2009 Share Posted September 3, 2009 Add the following two lines of code immediately after the first opening <?php tag to get php to help you - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911909 Share on other sites More sharing options...
rhodesa Posted September 3, 2009 Share Posted September 3, 2009 try something like this instead: <?php $user = "user"; $password = "password"; $host = "localhost"; $db = "db"; echo "Connecting..."; $conn = mysql_connect($host,$user,$password) or die("Problems connecting: " . mysql_error()); echo "Done<br />"; echo "Selecting DB..."; if(!mysql_select_db($db, $conn)) echo "Failed"; else echo "Done<br />"; mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911911 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 welll of course that doesn't echo anything. you have to enclose strings with quotes. echo "second"; is it still not echoing anything? Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911914 Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2009 Share Posted September 3, 2009 Except that php allows some extremely awful code to do something - Notice: Use of undefined constant first - assumed 'first' in your_file.php on line x first Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911916 Share on other sites More sharing options...
Phobios Posted September 3, 2009 Author Share Posted September 3, 2009 Now I see the error! It says: Fatal error: Call to undefined function mysql_connect() in /var/www/html/test.php on line 12 How do I fix this problem? edit: It still echoed first, but I have added quotation marks now since it gave me a warning... didn't think about that. Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911945 Share on other sites More sharing options...
rhodesa Posted September 3, 2009 Share Posted September 3, 2009 http://us3.php.net/manual/en/mysql.installation.php Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911948 Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 are you sure you have the PHP mysql package installed on your server? Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911949 Share on other sites More sharing options...
Phobios Posted September 3, 2009 Author Share Posted September 3, 2009 Thanks everyone for your help. Everything works fine now. Quote Link to comment https://forums.phpfreaks.com/topic/173025-solved-unknown-mysql_connect-problem/#findComment-911969 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.