+ Reply to Thread
Results 1 to 5 of 5

Thread: Fatal error: Call to a member function FetchRow() on a non-object

  1. #1
    quantentunnel is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    Fatal error: Call to a member function FetchRow() on a non-object

    Hi,
    I am new to PHP, AdoDB, SOAP... BUT having fun to try it out
    I tried to use your sample php code to run an upsert using records from a MySQL Database.

    Unfortunately when I run the php-skript I get the error:

    Fatal error: Call to a member function FetchRow() on a non-object in /pathtoskript/upsert.php on line 104

    Facts:
    OS: Linux dellnb 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/Linux

    PHP Version:
    m@dellnb:~/files$ php -v
    PHP 5.2.10-2ubuntu6 with Suhosin-Patch 0.9.7 (cli) (built: Oct 23 2009 16:30:10)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

    PHP skript (sorry for posting, attach-function did not work):
    PHP Code:
    #!/usr/bin/php 
    <?php

    // Start of code here

    error_reporting(E_ALL & ~ E_NOTICE);

    // Login to salesforce.com

    //this clears out your local PHP WSDL cache incase you may have been performing
    //tests against your development account or Sandbox account

    ini_set("soap.wsdl_cache_enabled""0");
    require_once (
    './php5-1.0.6/soapclient/SforcePartnerClient.php');
    require_once (
    './php5-1.0.6/soapclient/SforceHeaderOptions.php');

    // Salesforce Login information
    $wsdl './php5-1.0.6/soapclient/partner.wsdl.xml';
    $userName "XXXusername@username.deXXX";
    $password "XXXpasswordXXX";

    // Process of logging on and getting a salesforce.com session
    $client = new SforcePartnerClient();
    $client->createConnection($wsdl);
    $loginResult $client->login($userName$password);


    if (!
    $loginResult->passwordExpired)
    {
        
    // Connect to ADO database
        
    require_once ('./adodb5/adodb.inc.php');# load code common to ADOdb

        
    $conn ADONewConnection("mysql");

        
    //connect to new database
        
    $_ret $conn->Connect('localhost'"root""markus""mydatabase");

        if (
    $_ret)
        {

            
    // Set initial parameters
            
    $number_records 200;// set the amount of records to process at one time, and also the amont to increment the session variable by each iteration
            
    $record_count $number_records;
            
    $starting_record 1;// will start at the first record, then will increment by $number_records each iteration
            
    $tab "\t";
            
    $cr "\n";


            
    //Reset counters for accounts
            
    $accounts_created 0;
            
    $accounts_updated 0;
            
    $accounts_failed 0;

            
    //Cleans up old files from past runs and re-creates the /files folder
            //delete_directory('./files');
            //mkdir("./files", 0777);


            //Adds Run Date to File name
            
    $date date("mdy_hia");
            
    $savepath './files';

            
    //Creates log fiels which can be  emailed to distro list
            
    $data1 "Account" ',' "External Id" $cr;
            
    $file_created "$savepath/accounts_created_".$date.".csv";
            
    $fp fopen($file_created"a");// $fp is now the file pointer to file $filename
            
    fwrite($fp$data1);//    Write information to the file
            
    fclose($fp);

            
    $data2 "Account" ',' "External Id" $cr;
            
    $file_updated "$savepath/accounts_updated_".$date.".csv";
            
    $fp fopen($file_updated"a");// $fp is now the file pointer to file $filename
            
    fwrite($fp$data2);//    Write information to the file
            
    fclose($fp);

            
    $data2 "Account,External Id,Error Message" $cr;
            
    $file_failed "$savepath/accounts_failed_".$date.".csv";
            
    $fp fopen($file_failed"a");// $fp is now the file pointer to file $filename fwrite($fp, $data2);   //Write information to the file
            
    fclose($fp);

            while (
    $record_count == $number_records)
            {

                
    // Reset the php execution time to 20 seconds every time we get new
                // records from the database
                
    set_time_limit(20);

                
    //$sql = "SELECT smsid as \"SMSID__c\",
                //        text as \"text__c\"
                //        FROM q2sfdc
                //        WHERE ROWCOUNT BETWEEN $starting_record AND ($starting_record + ($number_records-1))
                //        ORDER BY ROWCOUNT";
                
    $sql "SELECT smid as \"smid__c\",
                        text as \"text__c\"
                        FROM q2sfdc
                        WHERE ROWCOUNT BETWEEN $starting_record AND ($starting_record + ($number_records-1))
                        ORDER BY ROWCOUNT"
    ;

                
    $recordSet $conn->Execute($sql);

                
    $all_fields = array();
                
    $i 0;
              
    ////////////////////////////////////////////////////////////////////
              
    while ($row $recordSet->FetchRow())  
                {
                    
    //$all_fields[$i]['OWNERID'] = $row['OWNERID'];
                    
    $all_fields[$i]['SMID__C'] = htmlspecialchars(stripslashes(strip_tags($row['SMID__C'])));
                    
    $all_fields[$i]['TEXT__C'] = htmlspecialchars($row['TEXT__C']);
                    
    // You can add addtional rows here if needed
                    
    $i++;
                }
    ////////////////////////////////////////////////////////////////////

                
    $record_count $i;

                
    $sObjects = array();

                foreach (
    $all_fields as $fieldset)
                {
                    
    $sObject = new sObject();
                    
    $sObject->type 'Terminal_Data__c'// Salesforce Table or object that you will perform the upsert on
                    
    $sObject->fields $fieldset;
                    
    array_push($sObjects$sObject);
                }
                
    //This passes the client = the login to sales force
                // the $sObjects = data to upsert
                // $file_updated = accounts which are updated
                // $file_created = accounts which are inserted
                // $file_failed =  accounts which failed
                
    $success upsert_accounts($client$sObjects$file_updated$file_created$file_failed);

                
    // Update the overall counts
                
    if (is_array($success))
                {
                    
    $accounts_created $accounts_created $success[0];
                    
    $accounts_updated $accounts_updated $success[1];
                    
    $accounts_failed =  $accounts_failed $success[2];
                }

                
    $starting_record $starting_record $number_records;

                
    ob_start();
                
    $total_record_count $total_record_count $record_count;
                echo 
    $total_record_count." records processed.";
                
    ob_end_flush();
            }

            
    // Close database connection after all rows have been retrieved
            
    if ($conn)
            {
                
    $conn->Close();
            }

        }
        else
        {
            
    // There was an error connecting to the database
            
    $msg 'Cannot connect to Database';
            
    $msg $msg 'Error: ' $conn->ErrorMsg();
            echo 
    $msg;
        }
    }
    else
    {
        echo 
    "Unable to connect to salesforce.com.";
    }




    /************************
    *  Salesforce Functions *
    *************************/
    function upsert_accounts($client$sObjects$file_updated$file_created$file_failed)
    {
        
    $accounts_created 0;
        
    $accounts_updated 0;
        
    $accounts_failed 0;
        try
        {
            
    // The upsert process
            
    $results $client->upsert("SMID__c"$sObjects);

            
    $k 0;

            
    // This loop processes $result to build the log files
            
    foreach ($results as $result)
            {
                
    // Build string from fields in $sObjects array
                // At this point, the record has already been upserted
                // We just need the data for the log file
                // The string is the same, regardless of the result
                
    $data2 $sObjects[$k]->fields['NAME'] . ", " $sObjects[$k]->fields['SMID__c'];

                if (
    $result->success)
                {
                    if (
    $result->created)
                    {
                        
    $accounts_created++;
                        
    file_put_contents($file_created$data2 "\n"FILE_APPEND);
                    }
                    else
                    {
                        
    $accounts_updated++;
                        
    file_put_contents($file_updated$data2 "\n"FILE_APPEND);
                    }
                }
                else
                {
                    
    $accounts_failed++;
                    
    // The errors object also contains fields and status_code
                    
    $errMessage $result->errors->message;
                    
    file_put_contents($file_failed$data2 ", " $errMessage "\n"FILE_APPEND);
                }
                
    $k++;
            }
            
    // Put the result counts into an array to pass back as the result.
            
    $success = array();
            
    array_push($success$accounts_created$accounts_updated$accounts_failed);
            return 
    $success;
            exit;
        }
        catch (
    exception $e)
        {
            
    // This is reached if there is a major problem in the data or with
            // the salesforce.com connection. Normal data errors are caught by
            // salesforce.com
            
    echo '' print_r($etrue) . '';
            return 
    false;
            exit;
        }
    }
    ?>

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Thanks for joining and I cleaned up your post a little.

    THat usually means that your path to ADOdb is incorrect.

    echo out the $sql before that line and run it in phpmyadmin to see if you get any results. That query was originally wrote for Oracle, not MySQL. I bet your query is not returning any records....

    so do this around line 104:

    PHP Code:


    echo $sql '<br />'
    while (
    $row $recordSet->FetchRow())  
    {
        
    //$all_fields[$i]['OWNERID'] = $row['OWNERID'];
        
    $all_fields[$i]['SMID__C'] = htmlspecialchars(stripslashes(strip_tags($row['SMID__C'])));
        
    $all_fields[$i]['TEXT__C'] = htmlspecialchars($row['TEXT__C']);
        
    // You can add addtional rows here if needed
        
    $i++;

    then run the script, you should see the sql in the browser, run that and see if you get any rows back.... that is your issue from what I can tell

    ~Mike

  3. #3
    quantentunnel is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4
    That's it! Thank you! The query do not fit to MySQL.
    After fixing that it come up other error messages. I assume that they are caused by similar Oracle/MySQL differences.

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /pathtoskript/upsert.php on line 104

    As I am not familiar with Oracle it is hard to figure out if any specific syntax was used due to the need of Oracle, PHP or ... I will further try around and if it ever works with MySQL I will post the syntax.

    Cheers and thanks again.

  4. #4
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Were you able to get this fixed sir?

    ~Mike

  5. #5
    quantentunnel is offline Junior Member
    Join Date
    Feb 2010
    Posts
    4

    ...working on it... :)

    ...I am still working on it. At the moment it works without a loop, means just a single query.

+ Reply to Thread

Similar Threads

  1. Fatal error: Class 'QueryResult'
    By sager@cmc.ca in forum Salesforce Coding Discussions
    Replies: 3
    Last Post: 02-08-2010, 10:40 AM
  2. Fatal error:[INVALID_LOGIN] INVALID_LOGIN:
    By lithiun in forum Salesforce PHP Tutorials
    Replies: 2
    Last Post: 10-07-2009, 03:18 PM
  3. SoapHeader fatal error
    By Baburaj in forum Salesforce PHP Tutorials
    Replies: 8
    Last Post: 05-23-2009, 09:10 AM
  4. Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from
    By monloi in forum Salesforce Coding Discussions
    Replies: 2
    Last Post: 02-18-2009, 07:26 AM
  5. php csv parse function
    By mike in forum PHP Snippets
    Replies: 3
    Last Post: 05-24-2008, 04:06 PM

Bookmarks

Posting Permissions

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

SEO by vBSEO 3.5.1