Jump to content

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?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.