Quickbooks Windows 与 PHP 同步 MySQL 镜像

Quickbooks Windows Sync with PHP MySQL Mirror

关于我和我的困境的一些前景知识:

好的。那么现在的问题是: 我已启动网络连接器并 运行ning 它指向此文件(已编辑以删除敏感内容)

<?php

/**
 * An example of how to mirror parts (or all of) the QuickBooks database to a MySQL database
 * 
 * 
 * *REALLY FREAKING IMPORTANT* WARNING WARNING WARNING WARNING
 * 
 * THE SQL MIRROR CODE IS BETA CODE, AND IS KNOWN TO HAVE BUGS!
 * 
 * With that said:
 * - If you're planning on using it in a production environment, you better be ready to do a lot of testing and debugging.
 * - Use a nightly build. There are known problems with the mirror code in the v1.5.2 or v1.5.3 releases of the code.
 * - There is absolutely no way I can troubleshoot problems for you without you posting your code. Dumps of the quickbooks_queue and quickbooks_log tables and/or phpMyAdmin access to your MySQL database is helpful also.
 * 
 * Nightly builds are available here:
 * https://code.intuit.com/sf/frs/do/viewRelease/projects.php_devkit/frs.php_devkit.latest_sources
 * 
 * IN ALL LIKELIHOOD, YOU SHOULD *NOT* BE USING THIS CODE. YOU SHOULD INSTEAD 
 * LOOK AT THE FOLLOWING SCRIPTS AND IMPLEMENT YOUR REQUEST/RESPONSE HANDLERS 
 * YOURSELF:
 *     docs/example_web_connector.php
 *     docs/example_web_connector_import.php
 * 
 * *REALLY FREAKING IMPORTANT* WARNING WARNING WARNING WARNING
 *
 *  
 * The SQL mirror functionality makes it easy to extract information from 
 * QuickBooks into an SQL database, and, if so desired, write changes to the 
 * SQL records back to QuickBooks automatically. 
 * 
 * You should look at my wiki for more information about mirroring QuickBooks 
 * data into SQL databases:
 *     http://wiki.consolibyte.com/wiki/doku.php/quickbooks_integration_php_consolibyte_sqlmirror
 * 
 * You should also read this forum post before even thinking about using this:
 *     http://consolibyte.com/forum/viewtopic.php?id=20
 * 
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */

// I always program in E_STRICT error mode with error reporting turned on... 
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

// Set the include path
require_once '../QuickBooks.php';

// You should make sure this matches the time-zone QuickBooks is running in
if (function_exists('date_default_timezone_set'))
{
    date_default_timezone_set('America/Edmonton');
}

// The username and password the Web Connector will use to connect with
$username = 'quickbooks';
$password = 'password';

// Database connection string
//
// You *MUST* start with a fresh database! If the database you use has any 
//    quickbooks_* or qb_* related tables in it, then the schema *WILL NOT* build 
//    correctly! 
//     
//     Currently, only MySQL is supported/tested. 
$dsn = 'my string removed';

// If the database has not been initialized, we need to initialize it (create 
//    schema and set up the username/password, etc.)
if (!QuickBooks_Utilities::initialized($dsn))
{
    header('Content-Type: text/plain');

    // It takes a really long time to build the schema... 
    set_time_limit(0);

    $driver_options = array(
        );

    $init_options = array(
        'quickbooks_sql_enabled' => true, 
        );

    QuickBooks_Utilities::initialize($dsn, $driver_options, $init_options);
    QuickBooks_Utilities::createUser($dsn, $username, $password);

    exit;
}

// What mode do we want to run the mirror in? 
//$mode = QuickBooks_WebConnector_Server_SQL::MODE_READONLY;        // Read from QuickBooks only (no data will be pushed back to QuickBooks)
//$mode = QuickBooks_WebConnector_Server_SQL::MODE_WRITEONLY;        // Write to QuickBooks only (no data will be copied into the SQL database)
$mode = QuickBooks_WebConnector_Server_SQL::MODE_READWRITE;        // Keep both QuickBooks and the database in sync, reading and writing changes back and forth)

// What should we do if a conflict is found? (a record has been changed by another user or process that we're trying to update)
$conflicts = QuickBooks_WebConnector_Server_SQL::CONFLICT_LOG;

// What should we do with records deleted from QuickBooks? 
$delete = QuickBooks_WebConnector_Server_SQL::DELETE_REMOVE;        // Delete the record from the database too
//$delete = QuickBooks_WebConnector_Server_SQL::DELETE_FLAG;         // Just flag it as deleted

// Hooks (optional stuff)
$hooks = array();

/*
// Hooks (optional stuff)
$hook_obj = new MyHookClass2('Keith Palmer');

$hooks = array(

    // Register a hook which occurs when we perform an INSERT into the SQL database for a record from QuickBooks
    // QuickBooks_SQL::HOOK_SQL_INSERT => 'my_function_name_for_inserts', 
    // QuickBooks_SQL::HOOK_SQL_INSERT => 'MyHookClass::myMethod',

    // Register a hook which occurs when we perform an UPDATE on the SQL database for a record from QuickBooks
    // QuickBooks_SQL::HOOK_SQL_UPDATE => 'my_function_name_for_updates',

    // Example of registering multiple hooks for one hook type 
    // QuickBooks_SQL::HOOK_PREHANDLE => array(
    //    'my_prehandle_function',
    //    array( $hook_obj, 'myMethod' ),
    //    ),

    // Example of using the hook factory to use a pre-defined hook
    // QuickBooks_SQL::HOOK_SQL_INSERT => QuickBooks_Hook_Factory::create(
    //    'Relay_POST',                                 // Relay the hook data to a remote URL via a HTTP POST
    //    'http://localhost:8888/your_script.php'),

    QuickBooks_SQL::SQL_INSERT => array(
        QuickBooks_Hook_Factory::create(
            'Relay_POST', 
            'http://localhost:8888/your_script.php', 
            array( '_secret' => 'J03lsN3at@pplication' ) ), 
        ), 
    );

class MyHookClass
{
    static public function myMethod($requestID, $user, $hook, &$err, $hook_data, $callback_config)
    {
        // do something here...
        return true;
    }
}

function my_prehandle_function($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
    //print('here we are!');
    return true;
}

class MyHookClass2
{
    protected $_var;

    public function __construct($var)
    {
        $this->_var = $var;
    }

    public function myMethod($requestID, $user, $hook, &$err, $hook_data, $callback_config)
    {
        //print('variable equals: ' . $this->_var);
        return true;
    }
}
*/

// 
$soap_options = array();

// 
$handler_options = array(
    'deny_concurrent_logins' => false,
    );

// 
$driver_options = array();

$ops = array(
    QUICKBOOKS_OBJECT_SALESTAXITEM, 
    QUICKBOOKS_OBJECT_SALESTAXCODE, 
    QUICKBOOKS_OBJECT_CUSTOMER, 
    QUICKBOOKS_OBJECT_VENDOR, 

    QUICKBOOKS_OBJECT_INVENTORYITEM, 

    QUICKBOOKS_OBJECT_TEMPLATE, 

    QUICKBOOKS_OBJECT_CUSTOMERTYPE, 
    QUICKBOOKS_OBJECT_VENDORTYPE, 
    QUICKBOOKS_OBJECT_ESTIMATE, 
    QUICKBOOKS_OBJECT_INVOICE, 
    QUICKBOOKS_OBJECT_CLASS, 

    QUICKBOOKS_OBJECT_INVOICE, 

    /*
    QUICKBOOKS_OBJECT_INVENTORYITEM, 
    QUICKBOOKS_OBJECT_NONINVENTORYITEM, 
    QUICKBOOKS_OBJECT_SERVICEITEM, 
    QUICKBOOKS_OBJECT_SHIPMETHOD, 
    QUICKBOOKS_OBJECT_PAYMENTMETHOD, 
    QUICKBOOKS_OBJECT_TERMS, 
    QUICKBOOKS_OBJECT_PRICELEVEL, 
    QUICKBOOKS_OBJECT_ITEM, 
    */

    QUICKBOOKS_OBJECT_PAYMENTMETHOD, 

    QUICKBOOKS_OBJECT_COMPANY, 
    QUICKBOOKS_OBJECT_HOST, 
    QUICKBOOKS_OBJECT_PREFERENCES,
    );

$ops_misc = array(        // For fetching inventory levels, deleted transactions, etc. 
    QUICKBOOKS_DERIVE_INVENTORYLEVELS,
    QUICKBOOKS_QUERY_DELETEDLISTS,
    QUICKBOOKS_QUERY_DELETEDTRANSACTIONS,
    // 'nothing', 
    );

// 
$sql_options = array(
    'only_import' => $ops,
    'only_add' => $ops, 
    'only_modify' => $ops, 
    'only_misc' => $ops_misc, 
    );

// 
$callback_options = array();

// $dsn_or_conn, $how_often, $mode, $conflicts, $users = null, 
//    $map = array(), $onerror = array(), $hooks = array(), $log_level, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
$Server = new QuickBooks_WebConnector_Server_SQL(
    $dsn, 
    '1 minute', 
    $mode, 
    $conflicts, 
    $delete,
    $username, 
    array(), 
    array(), 
    $hooks, 
    QUICKBOOKS_LOG_DEVELOP, 
    QUICKBOOKS_SOAPSERVER_BUILTIN, 
    QUICKBOOKS_WSDL,
    $soap_options, 
    $handler_options, 
    $driver_options,
    $sql_options, 
    $callback_options);
$Server->handle(true, true);

当我第一次 运行 时,它会加载一段时间并在我的数据库中生成 tables。然后它说:

Version:
PHP QuickBooks SOAP Server v2.0 at /docs/example_mysql_mirror.php

Message:
Invalid password for username: quickbooks

Description:
QBWC1040: Web connector did not provide a valid password for the given username. Job ending.

如果我查看数据库,它不是文档所说的 140 table,而且 quickbooks_user table 是空的。我的密码在 Quickbooks Web Connector 中输入正确。 我不知所措,我没有想法,google 搜索告诉我修改用户 table 但它是空的。 任何事情都会有所帮助。 -埃文

For method of simplicity I want to have a DB Sync to MYSQL from our Quickbooks file

这绝对是您可以选择的最复杂的设置。无论如何,让两个数据库同步并不简单。如果您想要简单,请不要使用 SQL 镜像并尝试将 QuickBooks 与 SQL 数据库同步。

这是一件极其复杂的事情,原因有很多:

  • 同步两者的代码是测试版——因此在 评论:“SQL 镜像代码是测试代码,并且众所周知 错误!"
  • QuickBooks 根本就不是 SQL-based,而且功能有限 XML-based API,所以真的没有办法完全同步 干净利落的 QuickBooks -- 必须进行大量翻译
  • QuickBooks API 甚至不允许访问它包含的所有数据, 所以很难获得完全 up-to-date 和可靠的同步

如果您想要一种简单可靠的方法,请遵循 quick-start 指南

If I look in the DB it is not the 140 tables that the docs says I have

然后出了点问题。请记住,这是测试版代码。如果您的服务器正确配置为记录 PHP/SQL/web 服务器错误,那么您可以检查错误日志并找出问题所在。

the quickbooks_user table is empty

根据我的上述评论,这是因为出了点问题。您需要删除表并再次 运行 它,并检查您的错误日志以找出问题所在。