Jump to content

[SOLVED] Error - No Database Selected


limitphp

Recommended Posts

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

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.

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?

 

 

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]

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.