php/mysql puzzler

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

    php/mysql puzzler

    I use the adodb_lite class and I'm getting curious results with a
    wrapper function I've written to insert an array in a table. The
    function has an optional parameter to verify columns (the array keys)
    before executing the statement. It runs this statement:

    "SHOW COLUMNS FROM `$table`"

    (I've added a larger code snippet below.)

    What is weird is that if I call the function more than once, this part
    of it will fail after the first call.

    What is weirder is that it works fine on my local server -- I only get
    the problem on my host's server.

    Anyone encounter a problem like this? One solution would be just to
    skip the column verification. But I suspect its symptomatic of some
    php or mysql setting that may have unintended consequence elsewhere.

    I should note that adodb_lite is called using a singleton pattern, so
    that the same object should be used each time this function is called.
    Could that have something to do with it? Also my host is PHP 4 and my
    local server PHP 5 (and may be using different versions of MySQL as
    well.)

    Any help will be appreciated. If you think this is a question better
    aimed at the mysql discussion group, let me know and I'll try there.

    Thanks,
    Tom


    Code Snippet:

    // Get DB Object
    $_ADOcx = amvc_ado_cx($db _name);

    // Set Fetch Mode
    $ADODB_FETCH_MO DE = ADODB_FETCH_ASS OC;

    // Check Table Columns
    if ( $_FLAG['check_cols'] )
    {
    // SQL Query
    $_SQL['check_cols'] = "SHOW COLUMNS FROM `$table`";

    // Run Query
    if ( !$_ADO_r = $_ADOcx->Execute($_SQ L['check_cols']) )
    {
    trigger_error(" unable to check columns for table [$table]:
    {$_SQL['check_cols']}", E_USER_WARNING) ;
    return 0;
    }

    // Sanity Check
    if ( !$_ADO_r->RecordCount( ) )
    {
    trigger_error(" No record count for table [$table]",
    E_USER_WARNING) ;
    return 0;
    }

    It fails right here, on the RecordCount (but only after first call.)

  • Tom

    #2
    Re: php/mysql puzzler

    Aha! In the course of writing out my problem here (below), I noted the
    different versions of PHP my server and my host's server were using.
    This was the first time I had taken note of it myself.

    Right after this, I changed my code so that it called the adodb_lite
    class by reference ( =& ). That solved it. This note on the PHP site
    confirms it:

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    Anyway, if nothing else, this speaks to the power of articulating your
    problem when nothing else seems to be working.



    On Nov 29, 11:34 am, "Tom" <klenw...@gmail .comwrote:
    I use the adodb_lite class and I'm getting curious results with a
    wrapper function I've written to insert an array in a table. The
    function has an optional parameter to verify columns (the array keys)
    before executing the statement. It runs this statement:
    >
    "SHOW COLUMNS FROM `$table`"
    >
    (I've added a larger code snippet below.)
    >
    What is weird is that if I call the function more than once, this part
    of it will fail after the first call.
    >
    What is weirder is that it works fine on my local server -- I only get
    the problem on my host's server.
    >
    Anyone encounter a problem like this? One solution would be just to
    skip the column verification. But I suspect its symptomatic of some
    php or mysql setting that may have unintended consequence elsewhere.
    >
    I should note that adodb_lite is called using a singleton pattern, so
    that the same object should be used each time this function is called.
    Could that have something to do with it? Also my host is PHP 4 and my
    local server PHP 5 (and may be using different versions of MySQL as
    well.)
    >
    Any help will be appreciated. If you think this is a question better
    aimed at the mysql discussion group, let me know and I'll try there.
    >
    Thanks,
    Tom
    >
    Code Snippet:
    >
    // Get DB Object
    $_ADOcx = amvc_ado_cx($db _name);
    >
    // Set Fetch Mode
    $ADODB_FETCH_MO DE = ADODB_FETCH_ASS OC;
    >
    // Check Table Columns
    if ( $_FLAG['check_cols'] )
    {
    // SQL Query
    $_SQL['check_cols'] = "SHOW COLUMNS FROM `$table`";
    >
    // Run Query
    if ( !$_ADO_r = $_ADOcx->Execute($_SQ L['check_cols']) )
    {
    trigger_error(" unable to check columns for table [$table]:
    {$_SQL['check_cols']}", E_USER_WARNING) ;
    return 0;
    }
    >
    // Sanity Check
    if ( !$_ADO_r->RecordCount( ) )
    {
    trigger_error(" No record count for table [$table]",
    E_USER_WARNING) ;
    return 0;
    }
    >
    It fails right here, on the RecordCount (but only after first call.)

    Comment

    Working...