<commit_before><?php
/**
 * Class responsible for synchronising local and remote database. Depends on MobiCore for settings.
 * 
 * @author Softcube Limited <<EMAIL>>
 * @link http://softcube.co Softcube
 * @copyright (c) 2013, All Rights Reserved
 * @version 1.0
 */
ini_set('display_startup_errors', 1);
include 'MobiCore.php';

class MobiSyncRemote
{

    public $local_db_instance;
    public $remote_db_instance;
    public $terminal_email;
    public $core_object;
    public $err;
    public function __construct()
    {
        $this->core_object = new MobiCore();
        $this->local_db_instance = $this->createInstance( 'local' );
        //$this->remote_db_instance = $this->createInstance( 'remote' );
        var_dump($this->getRemoteData());
    }
    
    /**
     * Establish a PDO database connection
     * @param string $location Either 'local' or 'remote', indicating whether it is connecting to a local database instance or a remote one
     * 
     * @return object returns a PDO database connection instance
     */
    private function createInstance( $location )
    {
        $instance = '';
        $core_obj = $this->core_object;
        
        switch ( $location )
        {
            case 'local':
                try
                {
                    $db_type = 'mysql';
                    $instance = new PDO(
                        $db_type.':dbname='.$core_obj->local_db_name.';host='.$core_obj->local_db_host, 
                        $core_obj->local_db_user, 
                        $core_obj->local_db_password,
                        array( PDO::ATTR_PERSISTENT => true ));
                
                } 
                catch (Exception $ex) 
                {
                    print 'Local Database Connection error: '.$ex->getMessage();
                    die();
                }
                
                break;
                
            case 'remote':
                try 
                {
                    $instance = new PDO(
                        $core_obj->remote_db_type.':dbname='.$core_obj->remote_db_name.';host='.$core_obj->remote_db_host, 
                        $core_obj->remote_db_user, 
                        $core_obj->remote_db_password,
                        array( PDO::ATTR_PERSISTENT => true ));
                } 
                catch (Exception $ex) 
                {
                    print 'Remote Database Connection error: '.$ex->getMessage();
                    die();
                }
                
                break;

                
        }
        
        return $instance;
    }
    
    /**
     * Gets all local survey answer records to uploaded to remote serer
     * 
     * @return string Returns a string of SQL insert statements for transmission to remote server
     */
    public function getRemoteData()
    {
        $qr = 'mysqldump -uroot -pAFtony19833 lime';
        
        exec($qr,$re);
        
        return $re;
        
        $tables = array();
        $survey_tables = array();
        $output = '';
        // Grab all active survey ids
        $db = $this->local_db_instance;
        $prep = $db->prepare( 'show tables' );
        $prep->execute();
        while ( $records = $prep->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_NEXT) )
        {
            $tables[] = $records[0];
        }
        
        
        
        // Extract table data
        foreach ( $tables as $table )
        {
            
            $query = 'select * from '.$table;
            $qr = $db->prepare($query);
            $qr->execute();
            $col_count = $qr->columnCount();<commit_msg>remote download done!<commit_after><?php
/**
 * Class responsible for synchronising local and remote database. Depends on MobiCore for settings.
 * 
 * @author Softcube Limited <<EMAIL>>
 * @link http://softcube.co Softcube
 * @copyright (c) 2013, All Rights Reserved
 * @version 1.0
 */
ini_set('display_startup_errors', 1);
include 'MobiCore.php';

class MobiSyncRemote
{

    public $local_db_instance;
    public $remote_db_instance;
    public $terminal_email;
    public $core_object;
    public $err;
    public function __construct()
    {
        $this->core_object = new MobiCore();
        $this->local_db_instance = $this->createInstance( 'local' );
        //$this->remote_db_instance = $this->createInstance( 'remote' );
        var_dump($this->getRemoteData());
    }
    
    /**
     * Establish a PDO database connection
     * @param string $location Either 'local' or 'remote', indicating whether it is connecting to a local database instance or a remote one
     * 
     * @return object returns a PDO database connection instance
     */
    private function createInstance( $location )
    {
        $instance = '';
        $core_obj = $this->core_object;
        
        switch ( $location )
        {
            case 'local':
                try
                {
                    $db_type = 'mysql';
                    $instance = new PDO(
                        $db_type.':dbname='.$core_obj->local_db_name.';host='.$core_obj->local_db_host, 
                        $core_obj->local_db_user, 
                        $core_obj->local_db_password,
                        array( PDO::ATTR_PERSISTENT => true ));
                
                } 
                catch (Exception $ex) 
                {
                    print 'Local Database Connection error: '.$ex->getMessage();
                    die();
                }
                
                break;
                
            case 'remote':
                try 
                {
                    $instance = new PDO(
                        $core_obj->remote_db_type.':dbname='.$core_obj->remote_db_name.';host='.$core_obj->remote_db_host, 
                        $core_obj->remote_db_user, 
                        $core_obj->remote_db_password,
                        array( PDO::ATTR_PERSISTENT => true ));
                } 
                catch (Exception $ex) 
                {
                    print 'Remote Database Connection error: '.$ex->getMessage();
                    die();
                }
                
                break;

                
        }
        
        return $instance;
    }
    
    /**
     * Gets all local survey answer records to uploaded to remote serer
     * 
     * @return string Returns a string of SQL insert statements for transmission to remote server
     */
    public function getRemoteData()
    {
        $qr = 'mysqldump -uroot -pAFtony19833 lime';
        
        $re = array();
        
        exec($qr,$re);
        
        return $re;
        
        $tables = array();
        $survey_tables = array();
        $output = '';
        // Grab all active survey ids
        $db = $this->local_db_instance;
        $prep = $db->prepare( 'show tables' );
        $prep->execute();
        while ( $records = $prep->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_NEXT) )
        {
            $tables[] = $records[0];
        }
        
        
        
        // Extract table data
        foreach ( $tables as $table )
        {
            
            $query = 'select * from '.$table;
            $qr = $db->prepare($query);
            $qr->execute();
            $col_count = $qr->columnCount();
{'fraction_non_alphanumeric': 0.11041268106039902, 'fraction_numerical': 0.003552883301448483, 'mean_word_length': 1.4004591669399804, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4105601', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1922, 'n_words': 455}