Jump to content

[SOLVED] mySQL cannot find database


Nomadic

Recommended Posts

Ok I have a test database named user up that looks like:

 

user_ID |user_NAME |user_PASS

1JoeTest

2BillTesting

3CarlATest

 

I am totally new to PHP/mySQL stuff and have been trying to figure out how to connect to a database. The problem is that when I run this code:

 

<?php

$username = "root";

$password = "<my password>";

$hostname = "localhost";

$dbh = mysql_connect($hostname, $username, $password)

or die("Unable to connect to mySQL server.");

print "Connected to mySQL server.<br>";

$selected = mysql_select_db("user",$dbh)

or die("Could not access user database.");

mysql_close($dbh);

?>

 

It is unable to connect to the database. This despite the fact that I can look at the database in SQLiteManager and clearly see it (and everything is correctly placed and spelled as far as I know). Earlier when I was trying this I got an error that said it could not find the 'user' database (even though I was viewing the 'user' database right in front of me). So any ideas what I am doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/138595-solved-mysql-cannot-find-database/
Share on other sites

Do you know the difference between a database and a table?

 

In short a database is a collection of tables. You seem to have a table called 'user' not a database.

 

Another thing: SQLiteManager is not for MySQL. It's for SQLite, which is totally different thing.

Do you know the difference between a database and a table?

 

In short a database is a collection of tables. You seem to have a table called 'user' not a database.

 

Another thing: SQLiteManager is not for MySQL. It's for SQLite, which is totally different thing.

 

The table is called userInfo (sorry for leaving that part out). So then how do I access and use the mySQL database on my server (I have wamp installed)?

To manage MySQL databases you can use phpMyAdmin (this comes with WAMPServer).

 

SQLiteManager is for SQLite databases only, these cannot be used with MySQL (or phpMyAdmin).

 

Thanks I think that got it. Guess I was confused with the whole database thing (not amazing since my previous database experience is with txt and ini files with a splash of xml). Thank you, all of you (and thanks for the amazingly quick responses).

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.