Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: Why doesn't fetch_array work on a remote server?

    It works on a local server but not on a remote.
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in e:\vhosts\...\files\getTableContents.php on line 15
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    fetch array does work on remote servers...
    what is thre code you are using to connect to the remote server

    we will need to see the code block from the open db to the fetch array, includign any variable you use to connect to the remote DB.

    but before you post the code I'd suggest you try to find out waht error message MySQL is throwing (id reccomend using the or die construct)

    as this is a PHP problem I'll move it to the PHP section

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    I'm supposed to fill this out right?
    PHP Code:
    mysql_connect(servername,username,password);
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      } 

    It's frustrating because I tried three or four different free servers and none of them works nor do they answer my emails quickly.
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    peronally I'd use the or die construct in one line...
    mysql_connect(servername,username,password) or die('Could not connect: ' . mysql_error());

    generally I'd pass it off to an error handler and decide what to do based on whether it was the development server (wher I dispaly the data, or a live server in which case you try ot handle the error as grqaxcefully as possible, let the developer know what went wrong but mask and MySQL or otehr messages from the user.

    wha thte error mesage is telling you is that you haven't suppolied a valid MySQL resource to the fetch array
    now that could be one of several reasons.
    the fetch array is being supplied with a null rowset.. ie you may need to check you have some results returned from mysql before tryign fetch_array
    it could mean that there is a problem in the SQL that you have't trapped
    it coudl be a problem in the defintion and opening of the MySQL connection.

    again without the code its impossible to say.

    Im not surprised that a free server doesn't respond to developer queries, beyond them making sure their server is working what else is there that they can or should do... after al you are connecting to them for free, how can they afford to give you help on developing your PHP scripts when they do
    don't get any cash from you. how do they pay their tech team to support you.

    I'd suggest you post all the code form you connection through to the line that is causing you problems, BUT NOT the whole script.. just the bits where you are trying to connect to MySQL upto the fetch_array

  5. #5
    Join Date
    Jul 2004
    Posts
    494
    I exported the database as a .sql file. However I suspect there's something wrong with the database itself that has to be opened once the username and password and server are called. Am I right on this one? How do I do that?
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what makes you think its a problem with the SQL or the data?

    the error mesage you reported was:
    supplied argument is not a valid MySQL result resource in e:\vhosts\...\files\getTableContents.php on line 15

    so my interpretation of that is that you supplied a parameter to the fetch_array that was invalid.

    So my guess is
    that either the connection/db/query isn't valid; but because you haven't supplied the code (it could be that the function is using the default MySQL connection and that isn't valid, or you haven't supplied the resultset from the mysql_query function.

    not knowing how you have done your error trapping there is no way to know whether its a typo (so as far as PHP is concerned you have supplied a blank variable to the fetch_array function, or if there is a fault with the MySQL calls upstream of fetch_array)

    so to diagnose this fault I'd suggest you post the code from the
    mysql_connect function right on through to the fetch_array

    I'm assuming you have proved your connection , db & password details are correct....

    dont post the whole PHP script.. just those bits

  7. #7
    Join Date
    Jul 2004
    Posts
    494
    Quote Originally Posted by healdem
    what makes you think its a problem with the SQL or the data?

    the error mesage you reported was:
    supplied argument is not a valid MySQL result resource in e:\vhosts\...\files\getTableContents.php on line 15

    so my interpretation of that is that you supplied a parameter to the fetch_array that was invalid.

    So my guess is
    that either the connection/db/query isn't valid; but because you haven't supplied the code (it could be that the function is using the default MySQL connection and that isn't valid, or you haven't supplied the resultset from the mysql_query function.

    not knowing how you have done your error trapping there is no way to know whether its a typo (so as far as PHP is concerned you have supplied a blank variable to the fetch_array function, or if there is a fault with the MySQL calls upstream of fetch_array)

    so to diagnose this fault I'd suggest you post the code from the
    mysql_connect function right on through to the fetch_array

    I'm assuming you have proved your connection , db & password details are correct....

    dont post the whole PHP script.. just those bits
    Error: No database selected
    Compare bible texts (and other tools):
    TheWheelofGod

  8. #8
    Join Date
    Apr 2008
    Location
    West Sussex
    Posts
    19
    It would help me if you posted the script, always find it easier to understand what the person is trying to do :P

  9. #9
    Join Date
    Jul 2004
    Posts
    494
    Here it is:
    PHP Code:
    $con mysql_connect("","",""); //mysql_connect(servername,username,password);
    if (!$con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("boti_book"$con);

    $sql "SELECT * FROM boti_css WHERE page_num = '".$i."'";
    $result mysql_query($sql) OR exit( 'Error: ' mysql_error() );
    //echo $sql;

    while($row mysql_fetch_array($result)) 
    Compare bible texts (and other tools):
    TheWheelofGod

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    when switching between a development server and live server I tend to use a define rather than a variable to contain such things as password, servers and other config stuff.

    I'm assuming you have set the server, user and password to nothing to hide them from the world on this site, so lets assume you have proven you connection works

    as a general point Im not convinced this script is bombproof enough (at least during development)

    Code:
    set Error_Level(E_ALL) // this should be reduced or removed in the live server
    $con = mysql_connect($servername,$username,$password) or die ("Script:$scriptname<BR>\n"Failed to open Connection.<BR>\n
    MySQL Error:".mysql_errno()."<BR>\nError Message:".mysql_error());
    
    mysql_select_db("boti_book", $con)  or die ("Script:$scriptname<BR>\n"Failed to Select DB.<BR>\n
    MySQL Error:".mysql_errno()."<BR>\nError Message:".mysql_error());
    
    $sql = "SELECT * FROM boti_css WHERE page_num = '".$i."'";
    $result = mysql_query($sql)  or die ("Script:$scriptname<BR>\n"Failed to Perform select.<BR>\n
    MySQL Error:".mysql_errno()."<BR>\nError Message:".mysql_error()."<BR>\nSQL:".$sql);
    if (@mysql_num_rows($result)>0)
    { while($row = mysql_fetch_array($result)) 
      ....
    } else // we found no rows
    { //if required insert code to handle that .. or to report that
    }
    have a look at error handling at w3schools

    if you have a config file that sets your local settings for this script
    eg if running on server X use these values, ServerY....
    you can then DEFINE appropriate values for the script

    eg code schematic
    Code:
    if development server
    { define('HOST', 'localhost');          //server host running database
      define('USERID', '*******');	     //normal account
      define('PWD', '!!!!!!');                 //Password on that account
      define('ERRORREPORTING',E_ALL) //report level for development server
      ...
    } else
    {define('HOST', 'url.to.db.server');          //server host running database
      define('USERID', '#######');	     //normal account
      define('PWD', '');                 //Password on that account
      define('ERRORREPORTING','0')      //report no errors on production server
      ...
    } 
    //you can then use these values in your scripts
    //EG
    //set Error_Level(ERRORREPORTING)
    //$con = mysql_connect(HOST,USERID,PWD) or die (.....)
    by custom defines in PHP are declared as all upper case

  11. #11
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    The error you are getting is indicative of a failed SQL query. Hence $result is not being filled out and mysql_fetch_array can't work on a non-valid mysql resultset.

    So, if you're confident that you have been able to connect to the server correctly, then I suggest investigating the tables/database because you're not getting a valid result from your query.

  12. #12
    Join Date
    Jul 2004
    Posts
    494
    when switching between a development server and live server I tend to use a define rather than a variable to contain such things as password, servers and other config stuff.

    I'm assuming you have set the server, user and password to nothing to hide them from the world on this site, so lets assume you have proven you connection works

    as a general point Im not convinced this script is bombproof enough (at least during development)

    PHP Code:
    set Error_Level(E_ALL// this should be reduced or removed in the live server
    $con mysql_connect($servername,$username,$password) or die ("Script:$scriptname<BR>\n"Failed to open Connection.<BR>\n
    MySQL Error
    :".mysql_errno()."<BR>\nError Message:".mysql_error());

    mysql_select_db("
    boti_book", $con)  or die ("Script:$scriptname<BR>\n"Failed to Select DB.<BR>\n
    MySQL Error:"
    .mysql_errno()."<BR>\nError Message:".mysql_error());

    $sql "SELECT * FROM boti_css WHERE page_num = '".$i."'";
    $result mysql_query($sql)  or die ("Script:$scriptname<BR>\n"Failed to Perform select.<BR>\n
    MySQL Error
    :".mysql_errno()."<BR>\nError Message:".mysql_error()."<BR>\nSQL:".$sql);
    if (@mysql_num_rows(
    $result)>0)
    { while(
    $row = mysql_fetch_array($result)) 
      ....
    } else // we found no rows
    { //if required insert code to handle that .. or to report that

    have a look at error handling at w3schools

    if you have a config file that sets your local settings for this script
    eg if running on server X use these values, ServerY....
    you can then DEFINE appropriate values for the script

    eg code schematic
    PHP Code:
    if development server
    define('HOST''localhost');          //server host running database
      
    define('USERID''*******');         //normal account
      
    define('PWD''!!!!!!');                 //Password on that account
      
    define('ERRORREPORTING',E_ALL//report level for development server
      
    ...
    } else
    {
    define('HOST''url.to.db.server');          //server host running database
      
    define('USERID''#######');         //normal account
      
    define('PWD''');                 //Password on that account
      
    define('ERRORREPORTING','0')      //report no errors on production server
      
    ...

    //you can then use these values in your scripts
    //EG
    //set Error_Level(ERRORREPORTING)
    //$con = mysql_connect(HOST,USERID,PWD) or die (.....) 
    by custom defines in PHP are declared as all upper case.
    ************************************************** *******

    I was having difficulty understanding the syntax so I rewrote what you said with php tags. But It's still not clear to me.

    I also have a few more questions. How would the server know from which directory to grab the database? Do the servers allow me to create and insert Database and tables?
    Compare bible texts (and other tools):
    TheWheelofGod

  13. #13
    Join Date
    Jul 2004
    Posts
    494
    Is it like this?
    PHP Code:
    set Error_Level(E_ALL// this should be reduced or removed in the live server
    $con mysql_connect($servername,$username,$password) or die ("Script:".$scriptname."<BR />\nFailed to open Connection.<BR />\nMySQL Error:".mysql_errno()."<BR>nError Message:".mysql_error());

    mysql_select_db("boti_book"$con)  or die ("Script:".$scriptname."<BR />nFailed to Select DB.<BR />\n
    MySQL Error:"
    .mysql_errno()."<BR />\nError Message:".mysql_error());

    $sql "SELECT * FROM boti_css WHERE page_num = '".$i."'";
    $result mysql_query($sql)  or die ("Script:".$scriptname."<BR />\nFailed to Perform select.<BR />n
    MySQL Error:'"
    .mysql_errno()."<BR />nError Message:".mysql_error()."<BR />nSQL:".$sql);
    if (@
    mysql_num_rows($result)>0)
    { while(
    $row mysql_fetch_array($result)) 
      ....
    } else 
    // we found no rows
    //if required insert code to handle that .. or to report that

    By the looks of it the server seems to support odbc and not mysql:
    Warning: mysql_connect(): Access denied for user 'ODBC'@'
    Last edited by gilgalbiblewhee; 04-22-08 at 21:40.
    Compare bible texts (and other tools):
    TheWheelofGod

  14. #14
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ok so what do you think
    Code:
    Warning: mysql_connect(): Access denied for user 'ODBC'@'.........'
    means?

    what do you think that error message is trying to tell you?

    my take on it is that MySQL is explicitly telling you that Access is denied to a specific user from a specific location. Its an error from mysql.. as you woudl probably know if you included the mysql_errno() as suggested in the or die script above. That doesn't mean that ODBC connections are not allowed on that server (although why anyone would want to use ODBC to access MySQL in a PHP environment is beyond me)

    Its telling you that user ODBC from the specified host does not have sufficient permissions for the action you want to take.

    so you need to check to make sure that the userid and password supplied to you are correctly defined or declared.

    so $servername, $username, $password all need to be correctly defined.. make sure they are

    if they are then check you are using the correct user id and password combination for the appropriate server. if the server is under someone else's control they will have provided you a userid & password so make sure you assign those correctly.

    if the server is under your control then you need to define the user(s) and passwords appropriately. if you are administering your own MySQL server I'd strongly recommend that you download the MySQL tools (includes administrator & Query Browser.. both very useful tools in a development environment)

    if you have several different servers then a define is a good option in my books, but if you want to use variables that's fine. I've always felt happier using DEFINEs for static config data, but each to their own.

  15. #15
    Join Date
    Jul 2004
    Posts
    494
    Ok. Now I understand what went wrong. The remote server needed me to name the database with username and password.

    Now that that's solved there's a problem with the timing. After 30 seconds the loading stops. And I need more time. What should I do?
    Compare bible texts (and other tools):
    TheWheelofGod

Posting Permissions

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