mySQL works on one server but not another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • |-|erc

    mySQL works on one server but not another

    Here's a test program that should output Members:0
    but instead I get "I cannot get data from the database!".
    Its as if the tables are not there but I have created them, does
    anyone know why this would work on one server but not another?

    <?php
    function sql_get_result( $sql) {
    global $link, $result;
    if ( !($result = mysql_query($sq l, $link))) { exit ("I cannot get data from database!<br>") ; }
    return $result;
    }

    include('config .php');
    $link = @mysql_connect ($DB_HOST, $DB_USER, $DB_PASS) or die ('SQL Connection troubles');
    mysql_select_db ($DB_DB);


    $sql = "SELECT count(*) from `members` WHERE 1";
    $result = sql_get_result( $sql);
    $counter = mysql_fetch_row ($result);
    echo "<br><b>Members : ". $counter[0];
    ?>

    Herc
    --
    Pot ~ the intellectual drug :-)-~
    how dangerous is 1 cigarette per week?


  • ben

    #2
    Re: mySQL works on one server but not another

    > Here's a test program that should output Members:0 but instead I get "I[color=blue]
    > cannot get data from the database!". Its as if the tables are not there
    > but I have created them, does anyone know why this would work on one
    > server but not another?[/color]

    Most of the reasons that I can think of would prevent the database from
    connecting in the first place.
    Have you got all error reporting turned on and can confirm that the
    mysql_connect and mysql_select_db are working OK?

    You can also try outputting mysql_error() after the connect, select_db and
    query to get more information on the problem.

    Ben

    Comment

    • |-|erc

      #3
      Re: mySQL works on one server but not another

      "ben" <usenet@bens-house.org.uk> wrote
      : > Here's a test program that should output Members:0 but instead I get "I
      : > cannot get data from the database!". Its as if the tables are not there
      : > but I have created them, does anyone know why this would work on one
      : > server but not another?
      :
      : Most of the reasons that I can think of would prevent the database from
      : connecting in the first place.
      : Have you got all error reporting turned on and can confirm that the
      : mysql_connect and mysql_select_db are working OK?
      :
      : You can also try outputting mysql_error() after the connect, select_db and
      : query to get more information on the problem.
      :

      right if I change the login info I get "SQL Connection troubles" instead so its connecting.
      i removed the exit("I cannot get data") but now I just get blank results, I'll try to pin
      down the error further.

      Herc



      Comment

      • Kim André Akerø

        #4
        Re: mySQL works on one server but not another

        |-|erc wrote:
        [color=blue]
        > Here's a test program that should output Members:0
        > but instead I get "I cannot get data from the database!".
        > Its as if the tables are not there but I have created them, does
        > anyone know why this would work on one server but not another?
        >
        > <?php
        > function sql_get_result( $sql) {
        > global $link, $result;
        > if ( !($result = mysql_query($sq l, $link))) { exit ("I cannot get
        > data from database!<br>") ; } return $result;
        > }
        >
        > include('config .php');
        > $link = @mysql_connect ($DB_HOST, $DB_USER, $DB_PASS) or die ('SQL
        > Connection troubles'); mysql_select_db ($DB_DB);
        >
        >
        > $sql = "SELECT count(*) from `members` WHERE 1";
        > $result = sql_get_result( $sql);
        > $counter = mysql_fetch_row ($result);
        > echo "<br><b>Members : ". $counter[0];
        > ?>[/color]

        Does the table exist with the same columns in the database on both
        servers?

        Also, if you add the following line in the above function, what comes
        up?
        echo mysql_error();

        --
        Kim André Akerø
        - kimandre@NOSPAM betadome.com
        (remove NOSPAM to contact me directly)

        Comment

        • |-|erc

          #5
          Re: mySQL works on one server but not another

          "Kim André Akerø" <kimandre@NOSPA Mbetadome.com> wrote in
          : |-|erc wrote:
          :
          : > Here's a test program that should output Members:0
          : > but instead I get "I cannot get data from the database!".
          : > Its as if the tables are not there but I have created them, does
          : > anyone know why this would work on one server but not another?
          : >
          : > <?php
          : > function sql_get_result( $sql) {
          : > global $link, $result;
          : > if ( !($result = mysql_query($sq l, $link))) { exit ("I cannot get
          : > data from database!<br>") ; } return $result;
          : > }
          : >
          : > include('config .php');
          : > $link = @mysql_connect ($DB_HOST, $DB_USER, $DB_PASS) or die ('SQL
          : > Connection troubles'); mysql_select_db ($DB_DB);
          : >
          : >
          : > $sql = "SELECT count(*) from `members` WHERE 1";
          : > $result = sql_get_result( $sql);
          : > $counter = mysql_fetch_row ($result);
          : > echo "<br><b>Members : ". $counter[0];
          : > ?>
          :
          : Does the table exist with the same columns in the database on both
          : servers?
          :
          : Also, if you add the following line in the above function, what comes
          : up?
          : echo mysql_error();

          No database selected.

          in config I have $DB_DB = 'u4f';
          and the database name is u4f
          I also tried setting $DB_DB to upload4free_u4f
          that's the account name.

          its a custom control panel with Globat but it looks like I set the database up correctly, it logs in the user ok.

          Herc



          Comment

          • Kim André Akerø

            #6
            Re: mySQL works on one server but not another

            |-|erc wrote:
            [color=blue]
            > "Kim André Akerø" <kimandre@NOSPA Mbetadome.com> wrote in
            > : |-|erc wrote:
            > :
            > : > Here's a test program that should output Members:0
            > : > but instead I get "I cannot get data from the database!".
            > : > Its as if the tables are not there but I have created them, does
            > : > anyone know why this would work on one server but not another?
            > : >
            > : > <?php
            > : > function sql_get_result( $sql) {
            > : > global $link, $result;
            > : > if ( !($result = mysql_query($sq l, $link))) { exit ("I cannot get
            > : > data from database!<br>") ; } return $result;
            > : > }
            > : >
            > : > include('config .php');
            > : > $link = @mysql_connect ($DB_HOST, $DB_USER, $DB_PASS) or die
            > ('SQL : > Connection troubles'); mysql_select_db ($DB_DB);
            > : >
            > : >
            > : > $sql = "SELECT count(*) from `members` WHERE 1";
            > : > $result = sql_get_result( $sql);
            > : > $counter = mysql_fetch_row ($result);
            > : > echo "<br><b>Members : ". $counter[0];
            > : > ?>
            > :
            > : Does the table exist with the same columns in the database on both
            > : servers?
            > :
            > : Also, if you add the following line in the above function, what
            > comes : up?
            > : echo mysql_error();
            >
            > No database selected.
            >
            > in config I have $DB_DB = 'u4f';
            > and the database name is u4f
            > I also tried setting $DB_DB to upload4free_u4f
            > that's the account name.
            >
            > its a custom control panel with Globat but it looks like I set the
            > database up correctly, it logs in the user ok.[/color]

            What if you put that line right after the mysql_select_db () statement
            of yours? What error message comes up then?

            --
            Kim André Akerø
            - kimandre@NOSPAM betadome.com
            (remove NOSPAM to contact me directly)

            Comment

            • |-|erc

              #7
              Re: mySQL works on one server but not another

              "Kim André Akerø" <kimandre@NOSPA Mbetadome.com> wrote in ...
              : |-|erc wrote:
              :
              : > "Kim André Akerø" <kimandre@NOSPA Mbetadome.com> wrote in
              : > : |-|erc wrote:
              : > :
              : > : > Here's a test program that should output Members:0
              : > : > but instead I get "I cannot get data from the database!".
              : > : > Its as if the tables are not there but I have created them, does
              : > : > anyone know why this would work on one server but not another?
              : > : >
              : > : > <?php
              : > : > function sql_get_result( $sql) {
              : > : > global $link, $result;
              : > : > if ( !($result = mysql_query($sq l, $link))) { exit ("I cannot get
              : > : > data from database!<br>") ; } return $result;
              : > : > }
              : > : >
              : > : > include('config .php');
              : > : > $link = @mysql_connect ($DB_HOST, $DB_USER, $DB_PASS) or die
              : > ('SQL : > Connection troubles'); mysql_select_db ($DB_DB);
              : > : >
              : > : >
              : > : > $sql = "SELECT count(*) from `members` WHERE 1";
              : > : > $result = sql_get_result( $sql);
              : > : > $counter = mysql_fetch_row ($result);
              : > : > echo "<br><b>Members : ". $counter[0];
              : > : > ?>
              : > :
              : > : Does the table exist with the same columns in the database on both
              : > : servers?
              : > :
              : > : Also, if you add the following line in the above function, what
              : > comes : up?
              : > : echo mysql_error();
              : >
              : > No database selected.
              : >
              : > in config I have $DB_DB = 'u4f';
              : > and the database name is u4f
              : > I also tried setting $DB_DB to upload4free_u4f
              : > that's the account name.
              : >
              : > its a custom control panel with Globat but it looks like I set the
              : > database up correctly, it logs in the user ok.
              :
              : What if you put that line right after the mysql_select_db () statement
              : of yours? What error message comes up then?
              :

              Access denied for user 'u1'@'%' to database 'u4f'

              OK I found the problem, I named the database uf4! :o)

              Herc



              Comment

              Working...