mysql_select_db doesn't work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bettina@coaster.ch

    mysql_select_db doesn't work

    Hello,
    I'm trying to connect a DB but I can't. Can anybody help me?
    Here is the piece of code...

    <?php
    $verbindung = mysql_connect(" localhost", "coasters", "");
    if (!$verbindung) {
    die('Not connected : ' . mysql_error());
    }
    // make coaster the current db
    $db_selected = mysql_select_db ('coaster', $verbindung);
    if (!$db_selected) {
    die ('Can\'t use coaster : ' . mysql_error());
    }
    ?>

    I get the following message:
    Can't use coaster : Access denied for user ''@'localhost' to database
    'coaster'

    The connection to the server seems to work.
    I have installed WAMPP2 and I use Macromedia Dreamweaver. I save the
    file as PHP and I send it to my webserver. The DB is local under
    MySQL\data. Do I have to send the DB to the server where I test, too?

    Thanks

  • jimp@specsol.spam.sux.com

    #2
    Re: mysql_select_db doesn't work

    bettina@coaster .ch wrote:[color=blue]
    > Hello,
    > I'm trying to connect a DB but I can't. Can anybody help me?
    > Here is the piece of code...[/color]
    [color=blue]
    > <?php
    > $verbindung = mysql_connect(" localhost", "coasters", "");
    > if (!$verbindung) {
    > die('Not connected : ' . mysql_error());
    > }
    > // make coaster the current db
    > $db_selected = mysql_select_db ('coaster', $verbindung);
    > if (!$db_selected) {
    > die ('Can\'t use coaster : ' . mysql_error());
    > }
    > ?>[/color]
    [color=blue]
    > I get the following message:
    > Can't use coaster : Access denied for user ''@'localhost' to database
    > 'coaster'[/color]
    [color=blue]
    > The connection to the server seems to work.
    > I have installed WAMPP2 and I use Macromedia Dreamweaver. I save the
    > file as PHP and I send it to my webserver. The DB is local under
    > MySQL\data. Do I have to send the DB to the server where I test, too?[/color]
    [color=blue]
    > Thanks[/color]

    Specify a user that has access to coaster from localhost.

    --
    Jim Pennino

    Remove .spam.sux to reply.

    Comment

    • bettina@coaster.ch

      #3
      Re: mysql_select_db doesn't work

      Hi Jim,
      In PHPMyAdmin I've just defined the following:
      In DB webauth:
      user: bett
      password: sapto
      In DB mysql Table DB: a new entry for DB coaster with user bett
      In DB mysql Table User: a new entry for user bett

      Now the code:
      ?php
      $db_server = "localhost" ;

      /* Datenbankname */
      $db_name = "coaster";

      /* Datenbankuser */
      $db_user = "bett";

      /* Datenbankpasswo rt */
      $db_passwort = "sapto";

      /* Erstellt Connect zu Datenbank her */
      $db = @MYSQL_PCONNECT ($db_server,$db _user,$db_passw ort)
      or die ("Konnte keine Verbindung zur Datenbank herstellen");
      $db_select = @MYSQL_SELECT_D B($db_name);
      if($db_select)
      echo "Datenbank wurde ausgewählt";
      ?>

      the DB is local, but I've sent the php document to my webserver. Is it
      correct? because I cannot see it local...

      and I received the following:
      Konnte keine Verbindung zur Datenbank herstellen

      What can I do????

      Comment

      • Jerry Stuckle

        #4
        Re: mysql_select_db doesn't work

        bettina@coaster .ch wrote:[color=blue]
        > Hi Jim,
        > In PHPMyAdmin I've just defined the following:
        > In DB webauth:
        > user: bett
        > password: sapto
        > In DB mysql Table DB: a new entry for DB coaster with user bett
        > In DB mysql Table User: a new entry for user bett
        >
        > Now the code:
        > ?php
        > $db_server = "localhost" ;
        >
        > /* Datenbankname */
        > $db_name = "coaster";
        >
        > /* Datenbankuser */
        > $db_user = "bett";
        >
        > /* Datenbankpasswo rt */
        > $db_passwort = "sapto";
        >
        > /* Erstellt Connect zu Datenbank her */
        > $db = @MYSQL_PCONNECT ($db_server,$db _user,$db_passw ort)
        > or die ("Konnte keine Verbindung zur Datenbank herstellen");
        > $db_select = @MYSQL_SELECT_D B($db_name);
        > if($db_select)
        > echo "Datenbank wurde ausgewählt";
        > ?>
        >
        > the DB is local, but I've sent the php document to my webserver. Is it
        > correct? because I cannot see it local...
        >
        > and I received the following:
        > Konnte keine Verbindung zur Datenbank herstellen
        >
        > What can I do????
        >[/color]

        Are you saying the database is on your local machine but you're php page
        is on the server?

        If so, that won't work. PHP runs on the server, and in your PHP code
        "localhost" therefore refers to the server - not your local machine.

        Create the database on the server and ensure you have the correct
        permissions set.


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • bettina@coaster.ch

          #5
          Re: mysql_select_db doesn't work

          The DB is unter MySql/Data on my local server and I send the php doc to
          my webserver to test. How can I test local? Where should I save the php
          doc?

          Comment

          • Tony

            #6
            Re: mysql_select_db doesn't work

            bettina@coaster .ch wrote:[color=blue]
            > The DB is unter MySql/Data on my local server and I send the php doc
            > to my webserver to test. How can I test local? Where should I save
            > the php doc?[/color]

            If you're using "localhost" as the database host name, then the PHP script
            and the database will have to be on the same machine.

            --
            Tony Garcia
            Web Right! Development
            tony.NO@webrigh tdevelopment.SP AM.com


            Comment

            • Jerry Stuckle

              #7
              Re: mysql_select_db doesn't work

              bettina@coaster .ch wrote:[color=blue]
              > The DB is unter MySql/Data on my local server and I send the php doc to
              > my webserver to test. How can I test local? Where should I save the php
              > doc?
              >[/color]

              You need to run the php script on the machine on which the database
              resides. This means either creating the database on your server, or
              installing a web server on your system to test.

              "localhost" always refers to the machine on which the script or program
              is running. Since PHP runs on the server, it refers to the server.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • bettina@coaster.ch

                #8
                Re: mysql_select_db doesn't work

                what was installed really with wampp2? On Services I can see Apache,
                MySql (is this MySql Server?). Do I have to install something else? I
                have the feeling I need something else... I created a user and password
                in PHPMyAdmin for the different DBs... is that enough? How should I
                installed aweb server on my system?

                Comment

                Working...