0

我有以下代码部分,我正在努力从 Paypal 事务中写入 MySQL 数据库。我只包含了相关的 Zend DB 日志部分,Paypal 界面工作正常,根据数据输出。

$paypalLog = array(
'transactionId' => 'transactionId',
'transactionType'  => 'transactionType',
'paymentType'   => 'paymentType',
'orderTime' => 'orderTime',
'amt' => 'amt',
'currencyCode' => 'currencyCode',
'feeAmt' => 'feeAmt',
'taxAmt' => 'taxAmt',
'paymentStatus' => 'paymentStatus',
'pendingReason' => 'pendingReason',
'reasonCode' => 'reasonCode'
);    

$data = array(
        'transactionId' => $transactionId,
        'transactionType'  => $transactionType,
        'paymentType'   => $paymentType,
        'orderTime' => $orderTime,
        'amt' => $amt,
        'currencyCode' => $currencyCode,
        'feeAmt' => $feeAmt,
        'taxAmt' => $taxAmt,
        'paymentStatus' => $paymentStatus,
        'pendingReason' => $pendingReason,
        'reasonCode' => $reasonCode
        );

     $mapping = array(
        'message'   => 'message',
        'extra' => $data);

     print_r($mapping);

     $writer = new Zend\Log\Writer\Db($db, 'paypal', $paypalLog);
     $logger = new Zend\Log\Logger();
     $logger->addWriter($writer);
     $logger->info($mapping);

当我运行我的代码时,打印返回以下内容,因此数据可用

Array ( [message] => message [extra] => Array ( [transactionId] => 03V084280U905161H [transactionType] => expresscheckout [paymentType] => instant [orderTime] => 2013-02-12T01:16:40Z [amt] => 9.00 [currencyCode] => AUD [feeAmt] => 0.52 [taxAmt] => 0.00 [paymentStatus] => Completed [pendingReason] => None [reasonCode] => None ) )

我的表定义如下,并且我已授予用户完全权限。

CREATE TABLE `paypal` (
  `timestamp` varchar(45) DEFAULT NULL,
  `priority` varchar(45) DEFAULT NULL,
  `priorityName` varchar(45) DEFAULT NULL,
  `message` varchar(45) DEFAULT NULL,
  `transactionId` varchar(45) NOT NULL,
  `transactionType` varchar(45) DEFAULT NULL,
  `paymentType` varchar(45) DEFAULT NULL,
  `orderTime` datetime DEFAULT NULL,
  `amt` varchar(45) DEFAULT NULL,
  `currencyCode` varchar(45) DEFAULT NULL,
  `feeAmt` varchar(45) DEFAULT NULL,
  `taxAmt` varchar(45) DEFAULT NULL,
  `paymentStatus` varchar(45) DEFAULT NULL,
  `pendingReason` varchar(45) DEFAULT NULL,
  `reasonCode` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`transactionId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

但是,当我在 MySQL 方面运行跟踪时,它只是不断尝试插入空值。

130212 12:19:38    29 Connect   user@localhost on database
       29 Query INSERT INTO `paypal` () VALUES ()
       29 Quit  

欢迎任何想法!

4

2 回答 2

2

感谢 cathulhu 的投入,非常感谢,我通过以下方式完成了这项工作

  // Array of db columns
  $paypalLog = array('transactionId' => 'transactionId',
    'transactionType'  => 'transactionType',
    'paymentType'   => 'paymentType',
    'orderTime' => 'orderTime',
    'amt' => 'amt',
    'currencyCode' => 'currencyCode',
    'feeAmt' => 'feeAmt',
    'taxAmt' => 'taxAmt',
    'paymentStatus' => 'paymentStatus',
    'pendingReason' => 'pendingReason',
    'reasonCode' => 'reasonCode'
    );  

  // Map data into array matching column names
  $data = array(            
        'transactionId' => $transactionId,
        'transactionType'  => $transactionType,
        'paymentType'   => $paymentType,
        'orderTime' => $orderTime,
        'amt' => $amt,
        'currencyCode' => $currencyCode,
        'feeAmt' => $feeAmt,
        'taxAmt' => $taxAmt,
        'paymentStatus' => $paymentStatus,
        'pendingReason' => $pendingReason,
        'reasonCode' => $reasonCode
        );

     // Array to construct the DB logger table structure with extra columns
    $mapping = array(   
        'timestamp' => 'timestamp',
        'priority'  => 'priority',
        'priorityName'  => 'priorityName',
        'message'   => 'message',
        'extra' => $paypalLog);      

     // Array to log actual data
     $mylog = array(
        'message' => 'some msg',
        'extra' => $data);

     // Configure the write/logger and specify the array members to log
     $writer = new Zend\Log\Writer\Db($db, 'paypal', $mapping);
     $logger = new Zend\Log\Logger();
     $logger->addWriter($writer);
     $logger->info($mylog['message'], $mylog['extra']);

我现在从 MySQL 常规日志中看到了这个输出

Connect user@localhost on database
       54 Query INSERT INTO `paypal` (`timestamp`,`priority`,`priorityName`,`message`,`transactionId`,`transactionType`,`paymentType`,`orderTime`,`amt`,`currencyCode`,`feeAmt`,`taxAmt`,`paymentStatus`,`pendingReason`,`reasonCode`) VALUES ('2013-02-15T07:52:52+01:00','6','INFO','My log message','88L4229675348363C','expresscheckout','instant','2013-02-15T06:52:58Z','9.00','AUD','0.52','0.00','Completed','None','None')
       54 Quit  
于 2013-02-15T07:07:12.770 回答
1

尝试替换这一行:

$logger->info($mapping);

和:

$logger->info($mapping['message'], $mapping['extra']);

Zend/Logger 的 info 方法期望接收两个单独的参数。

编辑:

进一步查看您的代码,我发现了另一个问题。列图只是一种原型。您真正想要记录的是您的数据和一些日志消息,对吗?

    $mapping = array(
        'message'   => 'message',
         'extra' => $paypalLog);      // Not $data !

    $mylog = array(
        'message' => 'My log message',
        'extra' => $data);

进而:

    $writer = new \Zend\Log\Writer\Db($db, 'paypal', $mapping); // Writer needs mapping info, not data :-)
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info($mylog['message'], $mylog['extra']);    // ...and your log record goes here, to logger instance
于 2013-02-12T13:25:49.707 回答