limitphp Posted September 29, 2008 Share Posted September 29, 2008 I installed WAMPSERVER to setup a test machine to work on php and MYSQL. I keep getting the error: "No Database Selected". Here's the code I'm using: $con = mysql_connect("localhost"); mysql_select_db("Testdata"); $sql = "CREATE TABLE person ( FirstName varchar(15), LastName varchar(15), Age int )"; mysql_query($sql,$con); Does anyone know why I'm getting this error? Do you have to setup a DNS for the MYSQL database in the control panel? Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/ Share on other sites More sharing options...
aebstract Posted September 29, 2008 Share Posted September 29, 2008 mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("database"); You have to have your username/password to log in to your database. Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653200 Share on other sites More sharing options...
limitphp Posted September 29, 2008 Author Share Posted September 29, 2008 mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("database"); You have to have your username/password to log in to your database. This might sound silly, but I'm not sure what the username or password is. I just installed WAMPSERVER. I read somewhere that you can use mysql_connect("localhost","root"); But that didn't seem to work either. Is there a way to find out what the password/username is? I have WAMPSERVER running right now on my test machine. Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653224 Share on other sites More sharing options...
havik Posted September 29, 2008 Share Posted September 29, 2008 try to connect with mysql_connect('localhost', 'root', '') or die (mysql_error()); mysql_select_db ('databasename'); or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653234 Share on other sites More sharing options...
limitphp Posted September 29, 2008 Author Share Posted September 29, 2008 try to connect with mysql_connect('localhost', 'root', '') or die (mysql_error()); mysql_select_db ('databasename'); I tried the above, but I got the same "No Database selected" here's what my code looks like now: $con = mysql_connect('localhost', 'root', '') or die (mysql_error()); mysql_select_db ('Testdata'); $sql = "CREATE TABLE person ( FirstName varchar(15), LastName varchar(15), Age int )"; mysql_query($sql,$con); Maybe I'm not setting up the database Testdata correctly. Its int he same directory as my test website. I have my test website in C:/wamp/www/testwebsite/ I setup the database to be in the same location. I also tried putting it in C:/wamp/www/ Was I supposed to setup the DSN in the control panel using the ODBC? Or is that only with access databases? Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653318 Share on other sites More sharing options...
havik Posted September 29, 2008 Share Posted September 29, 2008 just wondering did u create a d-base called Testdata? try opening http://localhost/phpmyadmin i think wamp has got it (i know xampp does) Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653326 Share on other sites More sharing options...
Barand Posted September 29, 2008 Share Posted September 29, 2008 run this script to see what databases you have <?php mysql_connect('localhost') or die ("Connect error"); $res = mysql_query("SHOW DATABASES"); while ($row = mysql_fetch_row($res)) { echo $row[0], '<br/>'; } ?> You should get something like [pre] information_schema mysql test world [/pre] Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-653487 Share on other sites More sharing options...
limitphp Posted September 30, 2008 Author Share Posted September 30, 2008 just wondering did u create a d-base called Testdata? try opening http://localhost/phpmyadmin i think wamp has got it (i know xampp does) Thank you guys! Success! I had built the database in the SQLiteManager, not the phpMyAdmin. Once I built it in the phpMyAdmin it worked! I'm confused, though, what is the difference between the two? Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-654029 Share on other sites More sharing options...
wildteen88 Posted September 30, 2008 Share Posted September 30, 2008 They manage two different types of SQL databases. phpMyAdmin is used for managing MySQL Databaes. SQLiteManager is used for managing SQLite Databases Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-654036 Share on other sites More sharing options...
limitphp Posted September 30, 2008 Author Share Posted September 30, 2008 They manage two different types of SQL databases. phpMyAdmin is used for managing MySQL Databaes. SQLiteManager is used for managing SQLite Databases Oh, I see. Thanks alot guys, I appreciate the help. Link to comment https://forums.phpfreaks.com/topic/126321-solved-error-no-database-selected/#findComment-654039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.