SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Newbie Question: No Database Selected

    I'm getting the following error with this code below.

    Error performing query: No database selected

    I'm pretty sure it has something to do with the SQL variable, but I've tried everything I can, I even had the mySQL generate the code for me and it's still broken. It doesn't say Could Not Connect, so I konw it's connecting, but then the SQL is the next step, where I believe it's broken.

    What can I do do fix it?

    PHP Code:
    <?php 


    $server 
    "ipaddress"// this is the server address
    $username "username"// mysql username
    $password "password"// mysql password


    $link mysql_connect ($server$username$password)
    or die (
    "Could not connect");

    $sql 'SELECT * FROM `Learning` LIMIT 0, 30 ';

    $result mysql_query($sql$link);
    if (!
    $result) {
      echo(
    "<p>Error performing query: " mysql_error() . "</p>");
      exit();


    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
        echo(
    $row["Artist"] . " ");
        echo(
    $row["Title"] . " ");
        echo(
    $row["Year"] . "<br>");


    ?>

  2. #2
    SitePoint Enthusiast Mounty's Avatar
    Join Date
    Mar 2008
    Location
    UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to select the database before you can query the Learning table:

    mysql_select_db("Database");



  3. #3
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the better way would be:
    mysql_query('use database');
    mysql_select_db is not recommended.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    and… the better way then that would be to use pdo

  5. #5
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, I got it working.


Bookmarks

Posting Permissions

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