No database selected - mysql error

Hi All,

My system.

Im running a wamp install with MySql v5.018, Apache/2.0.55 & PHP/5.1.2

I cant connect to a mysql database I created on my localhost and get the error below in red:

You are connected
running query:
INSERT INTO domains(domain, sex, mail) values(‘website’, ‘male/female’, ‘email’)
[COLOR=“Red”]INSERT error


: No database selected[/COLOR]

I can access this db in mysql console & phpmyadmin as the root user with no password.
All privileges is granted to the root user.

Here is my php code,

<?php

//DB_CONNECTION
//$connect=mysql_connect(‘localhost’,‘user’,‘password’);
//$select_db=mysql_select_db(‘dbName’);

$connect=mysql_connect(‘localhost’,‘root’,‘’);
$select_db=mysql_select_db(‘p24’);

if ($connect===false)
{
mysql_error ();
}
else
{
print “You are connected <br/>”;
}

$query = “INSERT INTO domains(domain, sex, mail)
values(‘website’, ‘F’, ‘mail’)”;
print "running query: <br/>
$query<br/>
";
mysql_query($query, $connect)
or die ("INSERT error: ".mysql_error());

mysql_close($connect);

?>

All help appreciated!

Does the following work?

<?php
$rConn = mysql_connect('localhost', 'root');
if((false === is_resource($rConn)) || (false === mysql_select_db('p24', $rConn)))
{
    echo mysql_error();
    exit;
}
if(false === mysql_query("INSERT INTO domains (domain, sex, mail)VALUES('website', 'F', 'mail')"))
{
    echo mysql_error();
    exit;
}
mysql_close($rConn);
?>

thanks for the rapid response.

No, now i get this Unknown database ‘p24’

Seems like i cant access the db…anymore suggestions

OK, what do you get with the following code…

<?php
$rConn = mysql_connect('localhost', 'root');
if((false === is_resource($rConn)))
{
    echo mysql_error();
    exit;
}
$rResult = mysql_query('SHOW DATABASES', $rConn);
while ($aRecord = mysql_fetch_assoc($rResult)){
    echo '<p>', $aRecord['database'], '</p>';
}
mysql_close($rConn);
?>

I get a blank screen.

I just copy and pasted your code, was that correct?

echo ‘<p>’, $aRecord[‘database’], ‘</p>’;

should this not display my db name?

Sorry, there’s a typo in the code I supplied.

<?php
$rConn = mysql_connect('localhost', 'root');
if((false === is_resource($rConn)))
{
    echo mysql_error();
    exit;
}
$rResult = mysql_query('SHOW DATABASES', $rConn);
echo '<h4>', mysql_num_rows($rResult), ' database(s) found.</h4>';
while ($aRecord = mysql_fetch_assoc($rResult))
{
    echo '<p>', $aRecord['Database'], '</p>';
}
mysql_close($rConn);
?>

Im winning!

Now i get this displayed in my browser

[COLOR=“Red”]4 database(s) found.

information_schema

mysql

phpmyadmin

test[/COLOR]

I do not have a test db.

But i have more db’s that is not displaying.
How can access a db that i create with sql console?

i have a img of my mysql console displaying that there is more db’s, but i cant upload this pic. the site is blocking me.

Not sure I’m afraid, not really my forte.

Try creating a thread in the MySQL forum, they’re a great bunch and will solve this in a jiffy. :slight_smile:

Feel free to pop back though once you get the permissions issue sorted.

Good luck!

ok, thanks for your help!

promblem solved

I was accessing a mysql db over our server and not from my root machine where i created all the dbs that i cant see.

lol!! silly bug

thanks silver bullet for your input, appreciated!

Great news, I’m glad you got it sorted.

Check whether you have that db or not

Er, did you read the rest of the thread? :smiley: