Author Topic: [SOLVED] Error - No Database Selected  (Read 1163 times)

0 Members and 1 Guest are viewing this topic.

Offline limitphpTopic starter

  • Devotee
    • View Profile
[SOLVED] Error - No Database Selected
« on: September 29, 2008, 02:37:27 PM »
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:
Code: [Select]
$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?
« Last Edit: September 29, 2008, 02:44:13 PM by limitphp »

Offline aebstract

  • Devotee
    • View Profile
Re: Error - No Database Selected
« Reply #1 on: September 29, 2008, 02:45:20 PM »
Code: [Select]
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.
There is an area of the mind that could be called unsane, beyond sanity, and yet
not insane. Think of a circle with a fine split in it. At one end there's
insanity. You go around the circle to sanity, and on the other end of the
circle, close to insanity, but not insanity, is unsanity.

Offline limitphpTopic starter

  • Devotee
    • View Profile
Re: Error - No Database Selected
« Reply #2 on: September 29, 2008, 03:11:13 PM »
Code: [Select]
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

Code: [Select]
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.

Offline havik

  • Irregular
    • View Profile
Re: Error - No Database Selected
« Reply #3 on: September 29, 2008, 03:21:24 PM »
try to connect with
Code: [Select]
mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db ('databasename'); or die (mysql_error());

Offline limitphpTopic starter

  • Devotee
    • View Profile
Re: Error - No Database Selected
« Reply #4 on: September 29, 2008, 04:14:43 PM »
try to connect with
Code: [Select]
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:

Code: [Select]
$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?


Offline havik

  • Irregular
    • View Profile
Re: Error - No Database Selected
« Reply #5 on: September 29, 2008, 04:18:48 PM »
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)

Offline Barand

  • Sen . (ile || sei)
  • Staff Alumni
  • 'Mind Boggling!'
  • *
  • Gender: Male
  • php 4.3/5.1 MySql 5.0.1
    • View Profile
Re: Error - No Database Selected
« Reply #6 on: September 29, 2008, 07:35:21 PM »
run this script to see what databases you have

Code: [Select]
<?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

information_schema
mysql
test
world
« Last Edit: September 29, 2008, 07:37:00 PM by Barand »
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

Offline limitphpTopic starter

  • Devotee
    • View Profile
Re: Error - No Database Selected
« Reply #7 on: September 30, 2008, 02:10:15 PM »
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?

Online wildteen88

  • PHPFreaks Recommended
  • 'Insane!'
  • *
  • Gender: Male
    • View Profile
Re: Error - No Database Selected
« Reply #8 on: September 30, 2008, 02:13:38 PM »
They manage two different types of SQL databases.

phpMyAdmin is used for managing MySQL Databaes.
SQLiteManager is used for managing SQLite Databases

Offline limitphpTopic starter

  • Devotee
    • View Profile
Re: Error - No Database Selected
« Reply #9 on: September 30, 2008, 02:16:25 PM »
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. 

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.