DavidGS Posted December 22, 2007 Share Posted December 22, 2007 So I am learning PHP and I was reading over how PHP can connect to databases, so I created a MySQL database and wrote a small program in PHP to see if it can access the database. Assuming my MySQL username was "user" password was "password" and I was accessing a database named "exampledb", the code would be: DB::connect('mysql://user:password@localhost/exampledb'); BUT when I run the program in Firefox, instead of connecting to http://localhost/ it connects to http://www.localhost.com/ and I don't want that to happen. How can I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/ Share on other sites More sharing options...
asmith Posted December 22, 2007 Share Posted December 22, 2007 why don't you change it to the more simple form ? $conn = mysql_connect("localhost","user","password"); mysql_select_db("yourdatabase_name","conn"); Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/#findComment-421083 Share on other sites More sharing options...
DavidGS Posted December 22, 2007 Author Share Posted December 22, 2007 why don't you change it to the more simple form ? $conn = mysql_connect("localhost","user","password"); mysql_select_db("yourdatabase_name","conn"); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/#findComment-421089 Share on other sites More sharing options...
DavidGS Posted December 22, 2007 Author Share Posted December 22, 2007 It still does it! This is driving me nuts, even when I test to see if PEAR works it still redirects. <?php require 'DB.php'; if (class_exists('DB')) { print "ok"; } else { print "failed"; } ?> This code should print "OK" if PEAR's installed, but all it does (in order) is: 1. Tries connecting to localhost 2. Says it's transferring data from localhost 3. Says it's connecting to www.localhost.com 4. Says it can't find the server on www.localhost.com What is going on?! ??? I have WAMP Server installed and I am accessing the file by typing in http://localhost/peartest.php (the file's in the directory and everything). Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/#findComment-421147 Share on other sites More sharing options...
asmith Posted December 22, 2007 Share Posted December 22, 2007 show me your db.php code Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/#findComment-421151 Share on other sites More sharing options...
DavidGS Posted December 22, 2007 Author Share Posted December 22, 2007 show me your db.php code Do you mean the actual PEAR db.php file? Quote Link to comment https://forums.phpfreaks.com/topic/82795-solved-accessing-databases-on-localhost-url-changes-to-wwwlocalhostcom-instead/#findComment-421162 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.