No database selected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shelly

    No database selected

    I have identical names for the database, user and password on the local
    machine and on the remote site. I also have identical tables and info in
    the tables. It works perfectly on the local machine. On the remote site I
    get "No Database Selected". It happens in the mysql_query call.

    echo "ssLogin = " . $ssLogin . " ";
    $LoginRS = mysql_query($Lo ginRS__query, $ssLogin) or die(mysql_error ());
    echo "LoginRS = " . $LoginRS;

    This gives:
    ssLogin = Resource id #3 No Database Selected

    On both machines I have have a require file which is:

    <?php
    # FileName="Conne ction_php_mysql .htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_ssLog in = "localhost" ;
    $database_ssLog in = "the_database_n ame";
    $username_ssLog in = "the_userna me";
    $password_ssLog in = "the_passwo rd";
    $ssLogin = mysql_pconnect( $hostname_ssLog in, $username_ssLog in,
    $password_ssLog in) or die(mysql_error ());
    ?>

    I thought it might be the $hostname_ssLog in, that it had to be something
    else. However, if it is not localhost, then the mysql_pconnect fails.

    Any ideas?

    Shelly


  • Dave

    #2
    Re: No database selected

    Shelly (sheldonlg@asap-consult.com) decided we needed to hear...[color=blue]
    > I have identical names for the database, user and password on the local
    > machine and on the remote site. I also have identical tables and info in
    > the tables. It works perfectly on the local machine. On the remote site I
    > get "No Database Selected". It happens in the mysql_query call.
    >
    > echo "ssLogin = " . $ssLogin . " ";
    > $LoginRS = mysql_query($Lo ginRS__query, $ssLogin) or die(mysql_error ());
    > echo "LoginRS = " . $LoginRS;
    >
    > This gives:
    > ssLogin = Resource id #3 No Database Selected
    >
    > On both machines I have have a require file which is:
    >
    > <?php
    > # FileName="Conne ction_php_mysql .htm"
    > # Type="MYSQL"
    > # HTTP="true"
    > $hostname_ssLog in = "localhost" ;
    > $database_ssLog in = "the_database_n ame";
    > $username_ssLog in = "the_userna me";
    > $password_ssLog in = "the_passwo rd";
    > $ssLogin = mysql_pconnect( $hostname_ssLog in, $username_ssLog in,
    > $password_ssLog in) or die(mysql_error ());
    > ?>
    >
    > I thought it might be the $hostname_ssLog in, that it had to be something
    > else. However, if it is not localhost, then the mysql_pconnect fails.
    >
    > Any ideas?
    >
    > Shelly
    >[/color]
    While your test machine may have only one (default) database, your
    remote machine will probably require you to specify which db you
    want to use... you can do this right after you connect with a call
    such as
    $status = mysql_select_db ($database_ssLo gin, $ssLogin);

    As an aside, are you sure your webhost allows persistent connections?
    I wouldn't have thought so, but a few might I suppose.

    --
    Dave <dave@REMOVEbun dook.com>
    (Remove REMOVE for email address)

    Comment

    • Shelly

      #3
      Re: No database selected

      "Dave" <dave@REMOVEbun dook.com> wrote in message
      news:7hq7m2-p5t.ln1@fawlty. homelinux.net.. .[color=blue]
      > While your test machine may have only one (default) database, your
      > remote machine will probably require you to specify which db you
      > want to use... you can do this right after you connect with a call
      > such as
      > $status = mysql_select_db ($database_ssLo gin, $ssLogin);
      >
      > As an aside, are you sure your webhost allows persistent connections?
      > I wouldn't have thought so, but a few might I suppose.[/color]

      I had one already there:
      mysql_select_db ($database_ssLo gin, $ssLogin);
      $encryptedPassw ord = md5($_POST["password"]);
      $LoginRS__query =sprintf("SELEC T username, password, level, status
      FROM ssusername WHERE username='%s' AND password='%s'",
      get_magic_quote s_gpc() ? $loginUsername :
      addslashes($log inUsername),
      $encryptedPassw ord);
      $LoginRS = mysql_query($Lo ginRS__query, $ssLogin) or die(mysql_error ());

      where it fails.

      Here is a possiblity. Tell me what you think. On my local machine I am
      running PHP5 but I think the server is running PHP4.x

      Shelly

      [color=blue]
      >
      > --
      > Dave <dave@REMOVEbun dook.com>
      > (Remove REMOVE for email address)[/color]


      Comment

      • Dave

        #4
        Re: No database selected

        Shelly (sheldonlg@asap-consult.com) decided we needed to hear...[color=blue]
        > "Dave" <dave@REMOVEbun dook.com> wrote in message
        > news:7hq7m2-p5t.ln1@fawlty. homelinux.net.. .[color=green]
        > > While your test machine may have only one (default) database, your
        > > remote machine will probably require you to specify which db you
        > > want to use... you can do this right after you connect with a call
        > > such as
        > > $status = mysql_select_db ($database_ssLo gin, $ssLogin);
        > >
        > > As an aside, are you sure your webhost allows persistent connections?
        > > I wouldn't have thought so, but a few might I suppose.[/color]
        >
        > I had one already there:
        > mysql_select_db ($database_ssLo gin, $ssLogin);
        > $encryptedPassw ord = md5($_POST["password"]);
        > $LoginRS__query =sprintf("SELEC T username, password, level, status
        > FROM ssusername WHERE username='%s' AND password='%s'",
        > get_magic_quote s_gpc() ? $loginUsername :
        > addslashes($log inUsername),
        > $encryptedPassw ord);
        > $LoginRS = mysql_query($Lo ginRS__query, $ssLogin) or die(mysql_error ());
        >
        > where it fails.
        >
        > Here is a possiblity. Tell me what you think. On my local machine I am
        > running PHP5 but I think the server is running PHP4.x
        >
        > Shelly
        >[/color]
        I wouldn't have thought PHP version should matter in this case - more
        likely its a MySQL issue.

        I would try checking the return value from mysql_select_db . If you get
        false then that might indicate a permissions problem. e.g. with my host
        when I create a MySQL user I then have to associate that user with any
        database I want to use it with, as a seperate step - if thats not done
        then even though I can connect fine, selecting a database will fail
        until I associate the user...

        --
        Dave <dave@REMOVEbun dook.com>
        (Remove REMOVE for email address)

        Comment

        • Alvaro G Vicario

          #5
          Re: No database selected

          *** Shelly wrote/escribió (Sun, 22 May 2005 22:43:11 -0400):[color=blue]
          > mysql_select_db ($database_ssLo gin, $ssLogin);[/color]

          No error checking here?

          From manual:

          usage:

          bool mysql_select_db ( string database_name [, resource link_identifier ] )

          Returns TRUE on success or FALSE on failure.


          --
          -- Álvaro G. Vicario - Burgos, Spain
          -- http://bits.demogracia.com - Mi sitio sobre programación web
          -- Don't e-mail me your questions, post them to the group
          --

          Comment

          • Shelly

            #6
            Re: No database selected


            "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
            message news:19dv95vhhe 2kn.14tu5sxx67c v2.dlg@40tude.n et...[color=blue]
            > *** Shelly wrote/escribió (Sun, 22 May 2005 22:43:11 -0400):[color=green]
            >> mysql_select_db ($database_ssLo gin, $ssLogin);[/color]
            >
            > No error checking here?
            >
            > From manual:
            >
            > usage:
            >
            > bool mysql_select_db ( string database_name [, resource
            > link_identifier ] )[/color]

            This the generated code from Dreamweaver. I'll add a check.

            Shelly


            Comment

            • Shelly

              #7
              Re: No database selected

              > "Alvaro G Vicario" <alvaro_quitar_ remove@telecomp uteronline.com> wrote in[color=blue]
              > message news:19dv95vhhe 2kn.14tu5sxx67c v2.dlg@40tude.n et...[color=green]
              >> *** Shelly wrote/escribi? (Sun, 22 May 2005 22:43:11 -0400):[color=darkred]
              >>> mysql_select_db ($database_ssLo gin, $ssLogin);[/color]
              >>
              >> No error checking here?
              >>
              >> From manual:
              >>
              >> usage:
              >>
              >> bool mysql_select_db ( string database_name [, resource
              >> link_identifier ] )[/color]
              >
              > This the generated code from Dreamweaver. I'll add a check.
              >
              > Shelly[/color]

              I added:

              if (!mysql_select_ db($database_ss Login, $ssLogin)) {
              echo "The mysql_select_db returned FALSE";
              }

              and it echoed. You are correct. It is failing in mysql_select_db . No what
              do I do?

              Shelly


              Comment

              • Oli Filth

                #8
                Re: No database selected

                Shelly wrote:[color=blue]
                > I added:
                >
                > if (!mysql_select_ db($database_ss Login, $ssLogin)) {
                > echo "The mysql_select_db returned FALSE";
                > }
                >
                > and it echoed. You are correct. It is failing in mysql_select_db . No[/color]
                what[color=blue]
                > do I do?
                >[/color]

                Add:

                echo mysql_error();

                To find out what the problem is.

                --
                Oli

                Comment

                Working...