Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    3

    Unanswered: Newb Question-- Connecting to databases

    I am using PHP 5.2 / Apache 2.4 / MySQL 5.0, and using the book Beginning PHP5, Apache, MySQL Web Development by wrox. I am working on configuring php with mysql but one issue I'm having with MySQL is that many of my commands will return the Error 1046: No database selected.

    Here is an example of code

    C:\>mysql -u root -p
    Enter password: ********
    Welcome to the MySQL monitor..
    ..
    ..
    mysql>show tables;
    ERROR 1046 (3D000): No database selected
    mysql>SELECT user, host FROM user;
    ERROR 1046 (3D000): No database selected
    mysql>show databases;
    *---------*
    Database
    ----------
    information_schema
    mysql
    test
    --------
    3 rows...



    ------------

    As you can see I've got mysql installed and everything, and PHP works with mysql, but I don't know where this error message is coming from. What can I do to fix this? Keep in mind that I don't have an extensive background with setting up networks. Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at the USE <database> statement

    an alternative to consider is downloading the MYSQL administrator tools from the MySQL website.. this includes adminstrator, query browser amongst others

    if you are no up to speed with the MySQL command line then the adminstrator tool can be very useful
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Yes, as healdem says...
    There was nothing wrong with any of the commands you produced, but unfortunately you failed to tell the MySQL command line which database it was you wanted to perform those queries on.
    USE test;
    will allow you to use the 'test' database and you can then perform any queries you have against that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •