+ Reply to Thread
Page 4 of 7 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 68
This is a discussion on Salesforce PHP MySQL Database Replication Tool within the Salesforce PHP Tutorials forums, part of the Salesforce category; Originally Posted by nrwingate By the way, Nice Picture on force.com..... what
  1. #31
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Quote Originally Posted by nrwingate View Post
    By the way, Nice Picture on force.com.....
    what link did you see that at? Or was that in the email

  2. #32
    nrwingate is offline Junior Member
    Join Date
    Jul 2008
    Posts
    12

  3. #33
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    oh shoot what a terrible picture, I look like a fricken elephant !!

  4. #34
    nrwingate is offline Junior Member
    Join Date
    Jul 2008
    Posts
    12
    Hey Mike......

    I am pretty sure I have something out of whack with regards to the php/mysql connection..... here is the evidence....

    Fatal error: Call to undefined function mysql_connect() in C:\PHPIntegration\xampp\htdocs\mysql_check0.php on line 3

    I get this when I run the following ..... (from the php.net site)

    <?php
    // Connecting, selecting database
    $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
    or die('Could not connect: ' . mysql_error());
    echo 'Connected successfully';
    mysql_select_db('my_database') or die('Could not select database');
    // Performing SQL query
    $query = 'SELECT * FROM my_table';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    // Printing results in HTML
    echo "<table>\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
    echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
    }
    echo "</table>\n";
    // Free resultset
    mysql_free_result($result);
    // Closing connection
    mysql_close($link);
    ?>

    Thoughts on where that problem might exist...?

    Thanks,

  5. #35
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Yeah that is an issue with your installation!

    Sorry man I do not know that much about things like that

  6. #36
    Jumpaloo is offline Junior Member
    Join Date
    Jan 2010
    Posts
    1

    Error on line 68

    Hi,

    I followed all the instructions, but i get these error, when i try to run this script againts my sandbox or prod.

    Undefined property: stdClass::$types in D:\xampp\htdocs\salesforce_mysql_build.php on line 68

    Any suggestions?

    I also tried your Online Tool ,but get the message
    Warning: fopen(prod.sql) [function.fopen]: failed to open stream: Permission denied in /home/mike/public_html/mysqlbuild/index.php on line 26

    and
    Warning: fwrite(): supplied argument is not a valid stream resource in /home/mike/public_html/mysqlbuild/index.php on line 67

  7. #37
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Quote Originally Posted by Jumpaloo View Post
    Hi,

    I followed all the instructions, but i get these error, when i try to run this script againts my sandbox or prod.

    Undefined property: stdClass::$types in D:\xampp\htdocs\salesforce_mysql_build.php on line 68

    Any suggestions?

    I also tried your Online Tool ,but get the message
    Warning: fopen(prod.sql) [function.fopen]: failed to open stream: Permission denied in /home/mike/public_html/mysqlbuild/index.php on line 26

    and
    Warning: fwrite(): supplied argument is not a valid stream resource in /home/mike/public_html/mysqlbuild/index.php on line 67
    Sorry about the permissions issue. when I uploaded the build tool to my new site, I forgot to set the permissions on the folder.

    I just did that and just tested it and it worked. Please try it again and as for the error in the download it is probably because that was written against the old toolkit, 11. I will update it against the new tool kit

    let me know if it works for you, Mike

  8. #38
    skj4me is offline Junior Member
    Join Date
    Sep 2009
    Posts
    2

    Full SF replication script

    Not sure if people will find this script useful, but its a slight variation of the main Salesforce to mysql replication script.

    It essentially loops through every object in salesforce(Except those specified in its ignore section) and sync's it to a mysql database. You must have a database created via Mike's Salesforce schema replicator. Certain objects such as history cannot be sync'd so you may have to tweak the object ignore list a bit.

    You must preload the database(using the dataloader) with data up till todays date(or wtvr date you specify in the time-stamp). You must then create a file called mirror.info and save a time-stamp in the following format: 2010-01-21T15:05:55Z

    The script will then pull every record modified in Salesforce after that time stamp and sync it with your mysql database. The time-stamp will be updated at the completion of the script.

    Sorry if its a bit messy in terms of its screen output but it functions quite well and we have a Cron job setup to sync every half hour.

    One major flaw, it does not detect deleted records. Not really sure how that can be accomplished so any suggestions would be much appreciated!

    Hope this helps someone!


    PHP Code:
    <?php

    error_reporting
    (E_ERROR E_WARNING E_PARSE E_NOTICE);
    define("SOAP_CLIENT_BASEDIR""includes/soapclient");
    require_once (
    SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');

    $USERNAME "YOURLOGIN";

    $PASSWORD "YOURPASSWORD";

    $client = new SforcePartnerClient();
    $client->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
    $myloginresult $client->login($USERNAME$PASSWORD);

    $conn mysql_connect("URL""LOGIN""PASS") or die(mysql_error());
    mysql_select_db('SFmirror') or die(mysql_error());

    mysql_set_charset('utf8'$conn);

    //Start log file;
    if(!$logfile fopen("log.txt",'a+'))
    {
           echo 
    "Cannot open file ($filename)";
               exit;
    }
    //Get lastdatemodified from "mirror.info"
    if(!$file fopen("mirror.info",'r+'))
    {
           echo 
    "Cannot open file ($filename)";
               exit;
    }

    fwrite($logfile,"Starting Sync...\n");


    $lastdatemodified fgets($file);

    $lastdatemodified trim($lastdatemodified);

    echo 
    $lastdatemodified;

    if (isset(
    $client))
                {
                    
                    
                        
    // Retrieve all the objects in the organization
                   
    $result $client->describeGlobal();
                   
                    
    // Cycle through each object
                   
    foreach ($result->types as $objectType)
                   {
                           echo 
    "()";
                           echo 
    $objectType;
                           echo 
    "()";
                           
    $q "Select ";
                           
    $resultObject $client->describeSObject($objectType);
                              
                        
    // Cycle through each field
                      
    foreach ($resultObject->fields as $field)
                        {
                            if (
    $field->name == "Binary")
                            {
                                  
    $field->name "Binary__c";
                            }
                            
                            
    $q $q $field->name ","
                                
                        }
                       
                        
    $q substr($q0strlen($q) - 1);
                        
    $q $q " FROM ";
                          
    $q $q $objectType;
                          
                          
    $q $q " where LastModifiedDate > "$lastdatemodified;                                                        
                          
                          
    //ObjecType exceptions to Ignore. 
                          
    if(strcmp($objectType,"AccountHistory") == 
                              
    ||  strcmp($objectType,"AccountShare")== 0
                              
    ||  strcmp($objectType,"ActivityHistory") == 
                             
    ||  strcmp($objectType,"AsyncApexJob")== 
                             
    ||  strcmp($objectType,"Case__c")== 
                            
    ||  strcmp($objectType,"CaseHistory")== 
                            
    ||  strcmp($objectType,"CaseSolution")== 
                            
    ||  strcmp($objectType,"ContactHistory")== 
                            
    ||  strcmp($objectType,"ContractHistory")== 0  
                            
    ||  strcmp($objectType,"DocumentAttachmentMap")== 
                            
    ||  strcmp($objectType,"EmailStatus")== 
                            
    ||  strcmp($objectType,"EmailTemplate")== 
                            
    ||  strcmp($objectType,"Event")== 0
                            
    ||  strcmp($objectType,"FiscalYearSettings")== 
                            
    ||  strcmp($objectType,"GroupMember")== 
                            
    ||  strcmp($objectType,"LeadHistory")== 
                            
    ||  strcmp($objectType,"LeadHistory")== 
                            
    ||  strcmp($objectType,"Name")== 
                            
    ||  strcmp($objectType,"NoteAndAttachment")== 
                            
    ||  strcmp($objectType,"OpenActivity")== 
                            
    ||  strcmp($objectType,"OpportunityFieldHistory")== 
                            
    ||  strcmp($objectType,"OpportunityHistory")== 
                            
    ||  strcmp($objectType,"Period")== 
                            
    ||  strcmp($objectType,"ProcessInstanceHistory")== 
                            
    ||  strcmp($objectType,"ProcessInstanceStep")== 
                            
    ||  strcmp($objectType,"ProcessInstanceWorkitem")== 0  
                            
    ||  strcmp($objectType,"QueueSobject")== 
                            
    ||  strcmp($objectType,"Scontrol")== 
                            
    ||  strcmp($objectType,"SolutionHistory")== 
                            
    ||  strcmp($objectType,"UserLicense")== 
                            
    ||  strcmp($objectType,"UserPreference")== 
                            
    ||  strcmp($objectType,"UserRole")== 
                            
    ||  strcmp($objectType,"Vote")== 
                            
    )
                          {
                      

                          }

                          else
                          {
                               
                              
    $field_list = array();
                              
    //build an array of field names which correspond to the current objectType;
                              
    $field_list buildflist($field_list,$client,$objectType);
                            
    $queryOptions = new QueryOptions(500);
                              
    $response $client->query(($q), $queryOptions);
                              
                              if (
    $response->size 0)
                              {
                              
                                  
    mysql__update($response,$objectType,$field_list,$conn);
                                  
                                  while (!
    $response->done)
                                    {
                                        echo 
    "<pre>";
                                        echo 
    "batch";
                                        echo 
    "</pre>";
                                        
    set_time_limit(100);
                                     
    $response $client->queryMore($response->queryLocator);
                                        
    mysql__update($response,$objectType,$field_list,$conn);
                                      }
                              
                              }
                          }
                      
                       }
                       
                 }
    else
        {
            echo 
    "Error establishing mysql connection on attempted table synch. Exiting...";
            exit;
        }

    echo 
    "test2";

    include 
    'include/closedb.php';

        
    update_timestamp($file,$logfile);
        
    fwrite($logfile,"done");
        
    fclose($logfile);
        
    fclose($file);

    function 
    mysql__update($response,$objectType,$field_list,$conn)
    {
        if (
    $objectType == 'Case')
                              {
                          
    $objectType 'Case__c';
                              }
                          elseif (
    $objectType == 'Group')
                              {
                          
    $objectType 'Group__c';
                              }
                          else
                              {
                              
    $objectType $objectType;
                              }
        
        
        
        foreach(
    $response->records as $record)
        {
            
    $push_list = array();
            
            
    $query "SELECT Count(*) FROM " $objectType " WHERE ID = \"" $record->Id "\"";
        
            
    $cur_id $record->Id;
        
            
    array_push($push_list,$cur_id);
        
            
    $result mysql_query($query);
            if (!
    $result) {
                        die(
    'Invalid query: ' mysql_error());
                        }
                        
            
    $match mysql_fetch_assoc($result);
            
            foreach(
    $record->fields as $field)
            {
                
    array_push($push_list,$field);
                
    //$push_list = $push_list . $field . ",";

            
    }
            
            
    //Remove the last ',' from push_list

        
        
             //If for some reason $push_list and $field_list do not have the same amount of elements, then 
            //something is amiss. Time to exit...
            
    if(count($push_list) != count($field_list))
            {
                echo 
    "Push_list != Field_List Exiting......";
                exit;
            } 
            
            
    //If match is 1, then the record exists and we are going to do an update
            
    if($match['Count(*)'] == 1)
            {
                
    $updateq "UPDATE " $objectType " SET "
                
                for(
    $i=0;$i<count($push_list);$i++)
                {
                    if(
    $push_list[$i] != "")
                    {
                    
    $updateq $updateq $field_list[$i] . ' = "' addslashes($push_list[$i]) . '",';
                
                    }
                }
                
    $updateq substr($updateq0,-1);
                
                
    $updateq $updateq ' WHERE Id = "' $cur_id '"';
                
                
    //echo "<br />";
                //echo $updateq;
            
                
    $result mysql_query($updateq);
                if (!
    $result)
                         {
                        die(
    'Invalid query: ' mysql_error());
                        }    
                
            }
            
            
    //If match is 0, then the record does not exist and we are going to do an insert
            
    else
            {
                
    $insertq "INSERT INTO " $objectType "(";
                for(
    $i=0;$i<count($push_list);$i++)
                {
                    
    //Add field lists
                    
    if($push_list[$i] != "")
                    {            
                        
    $insertq $insertq $field_list[$i] . ",";
                    }
                }
                
                
    $insertq substr($insertq0, -1);
                
    $insertq $insertq ") VALUES (";
                
                for(
    $i=0;$i<count($push_list);$i++)
                {
                    
    //Add field lists
                    
    if($push_list[$i] != "")
                    {    
                            
    $insertq $insertq '"' addslashes($push_list[$i]) . '",';
                    }
                }

                
    $insertq substr($insertq0, -1);
                
    $insertq $insertq ")";
                
                    
    $result mysql_query($insertq);
            
                    if (!
    $result)
                         {
                        die(
    'Invalid query: ' mysql_error());
                        }    
                
                
    //echo $insertq;
            
    }
            
    //echo "<br />";

            //echo "<br />";
        
    }
        
        echo 
    $objectType;    
        echo 
    "<br />";
        echo 
    "done.";
    }



    function 
    buildflist($field_list,$client,$objectType)
    {
        
         
    // Retrieve the object definition
        
    $resultObject $client->describeSObject($objectType);
                  
         
    // Cycle through each field
          
    foreach ($resultObject->fields as $field)
           {
               
    $temp $field->name;
            
    array_push($field_list,$temp);
        }
        return 
    $field_list;
    }




    function 
    update_timestamp($file,$logfile)
    {
        echo 
    "updating timestamp....";
        
    $time getdate();
        
    $month;
        
    $year;
        
    $day;
        
    $hour;
        
    $min;
        
    $second;

         if(
    strlen($time['mon'])==1)
             {
                 
    $month '0' $time['mon'];    
             }
         else
             {
                 
    $month $time['mon'];
             }
         
         if(
    strlen($time['mday']) == 1)
             {
                 
    $day '0' $time['mday'];
             }
         else 
             {
                 
    $day $time['mday'];
              }
        if(
    strlen($time['hours']) == 1)
            {
                
    $hour '0' . ($time['hours']-1);
            }
        else 
            {
                
    $hour $time['hours'];
            }    
        if(
    strlen($time['minutes']) == 1)
            {
                
    $min '0' $time['minutes'];
            }    
        else 
            {
                
    $min $time['minutes'];
            }
        if(
    strlen($time['seconds']) == 1)
            {
                
    $second '0' $time['seconds'];
            }
        else
            {
                
    $second $time['seconds'];
            }
            
        
    $new_timestamp $time['year']."-".$month."-".$day."T".$hour.":".$min.":".$second."Z";
        
       
    rewind($file);
       
    fwrite($file,$new_timestamp);
       
    fwrite($logfile,$new_timestamp);
    }

    ?>

  9. #39
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Thanks for that!! I am going to clean up your post a little so the code is viewer friendly

  10. #40
    skj4me is offline Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Hey can't really edit the message. Can you replace the echo timestamp in the last part with
    rewind($file);
    fwrite($file,$new_timestamp);
    fwrite($logfile,$new_timestamp);

    Thanks for cleaning it up, at work and didnt have a chance to touch it up.

+ Reply to Thread
Page 4 of 7 FirstFirst ... 23456 ... LastLast

LinkBacks (?)

  1. Hits: 1
    12-04-2009, 05:55 AM
  2. Hits: 1
    12-03-2009, 05:50 AM
  3. Hits: 4
    11-11-2009, 06:37 AM
  4. Hits: 11
    10-08-2009, 02:42 AM
  5. Hits: 12
    10-07-2009, 10:20 AM
  6. Hits: 6
    09-23-2009, 05:58 AM
  7. Hits: 2
    09-12-2008, 05:08 AM
  8. Hits: 1
    08-06-2008, 05:09 PM
  9. Hits: 1
    06-13-2008, 09:49 AM
  10. Hits: 14
    01-10-2008, 05:58 PM
  11. Hits: 1
    01-08-2008, 10:26 AM
  12. Hits: 1
    12-19-2007, 03:08 AM
  13. Hits: 1
    09-20-2007, 11:51 AM
  14. Hits: 1
    09-04-2007, 12:46 PM
  15. Hits: 3
    09-04-2007, 09:30 AM
  16. Hits: 1
    08-25-2007, 11:46 PM
  17. Hits: 2
    08-20-2007, 10:49 AM
  18. Hits: 101
    08-10-2007, 01:58 AM
  19. Hits: 49
    08-09-2007, 11:53 AM

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.2