【问题标题】:get mysql query to work with class with namespaces让 mysql 查询与具有命名空间的类一起工作
【发布时间】:2015-05-04 20:18:48
【问题描述】:

我正在为 SEPA 直接借记创建一个 XML 文件。

我正在使用https://github.com/dmitrirussu/php-sepa-xml-generator 并且示例工作正常,但我似乎无法在 MYSQL 中使用它...

我使用 composer 通过 composer.json 安装。

示例工作:

<?php
require 'vendor/autoload.php';

//When you start to generate a SEPA Xml File, need to choose PAIN
$directDebitTransaction = \SEPA\XMLGenerator::PAIN_008_001_02;// For Direct Debit transactions is By Defaut

$sepa = SEPA\Factory\XMLGeneratorFactory::createXmlGeneratorObject($directDebitTransaction)->addXmlMessage(
    SEPA\Factory\XMLGeneratorFactory::createXMLMessage()
        ->setMessageGroupHeader(
        SEPA\Factory\XMLGeneratorFactory::createXMLGroupHeader()
            ->setMessageIdentification(1)
            ->setInitiatingPartyName('Amazing SRL ???? ыаывпавпва '))
            ->addMessagePaymentInfo(
        SEPA\Factory\XMLGeneratorFactory::createXMLPaymentInfo()
            ->setPaymentInformationIdentification(6222)
            ->setSequenceType('RCUR')
            ->setCreditorAccountIBAN('MD24 AG00 0225 1000 1310 4168')
            ->setCreditorAccountBIC('AABAFI42')
            ->setCreditorName('Amazing SRL')
            ->setCreditorSchemeIdentification('FR07ZZZ519993')
            ->setRequestedCollectionDate('2013-08-06')
            ->setAggregatePerMandate(true) //Default Transaction aggregation option = true
/* TRANSACCION - 1 */
            ->addDirectDebitTransaction( //First transaction
            SEPA\Factory\XmlGeneratorFactory::createXMLDirectDebitTransaction()
                ->setInstructionIdentification(3)
                ->setEndToEndIdentification(3)
                ->setInstructedAmount(100.5)
                ->setDebtorName('Roy SRL')
                ->setDebitIBAN('FR14 2004 1010 0505 0001 3M02 606')
                ->setDebitBIC('AABAFI22') //Optional
                ->setMandateIdentification('SDD000000016PFX0713') //unique Identifier
                ->setDateOfSignature('2013-08-03')
                ->setCurrency('EUR')
                ->setDirectDebitInvoice(122)
           )
/* TRANSACCION - 2 */
// ...
/* TRANSACCION - 3 */
// ...
/* TRANSACCION - N */
// ...
    )
);

/* this is the part I need to use to REPLACE the transactions parts above */
$mysqli = new mysqli("localhost","root","","test");
if ($result = $mysqli->query("SELECT * FROM test"))
{
    while ($data = $result->fetch_object())
    {
        /*
        * here we get the data needed for the addDirectDebitTransaction()
        */
    }
}
$result->free();
$mysqli->close();

/* save XML */
$sepa->view()->save(realpath(__DIR__) .'/test.xml');

/* EOF */

正如我所说,这可行,但我不太了解命名空间,而且我无法做这么简单的事情......

请帮忙...

【问题讨论】:

    标签: php mysql xml


    【解决方案1】:

    您使用的不是 XML,而是 SEPA。 XML 仅间接用作序列化格式。

    您调用生成 SEPA 消息的特定 PHP 库的方法。

    也就是说,首先生成付款信息并将其存储到变量中。使用循环添加交易、生成消息并附加支付信息。

    【讨论】:

    • 这就是我想要的,但是如何调用来添加交易?那是我从上面的代码中不知道的。
    • 我将内容保存在 var $sepa 中,但在 de while 循环中...如何添加数据?我想知道怎么做:$sepa->[WHAT HERE?]->addDirectDebitTransaction($object_generated_from_inside_the_query)
    • SEPA\Factory\XMLGeneratorFactory::createXMLPaymentInfo() 创建付款信息。这用作SEPA\Factory\XMLGeneratorFactory::createXMLMessage() 创建的sepa 消息的-&gt;addMessagePaymentInfo() 的参数。拆分嵌套函数调用!
    • 拆分嵌套函数调用! .... 为什么你认为我在这里?我不知道该怎么做...
    【解决方案2】:

    我知道这个问题已经三岁了,但也许我们可以帮助某人,发现这个解释:

    directDebitTransaction aggregation in SEPA SDD XML Generator

    $paymentInfo = SEPA\Factory\XMLGeneratorFactory::createXMLPaymentInfo();
    
    $transactions = array(1, 2, 3, 4, 5);
    $a = 0;
    //add payment info transactions
    foreach($transactions as $t)
    {
        $paymentInfo->addDirectDebitTransaction(
            SEPA\Factory\XmlGeneratorFactory::createXMLDirectDebitTransaction()
                ->setInstructionIdentification(++$a)
                ->setEndToEndIdentification(++$a)
                ->setInstructedAmount(100.5)
                ->setDebtorName('DVORAK')
                ->setDebitIBAN('FR14 2004 1010 0505 0001 3M02 606')
                ->setDebitBIC('AABAFI22')
                ->setMandateIdentification('SDD000000016PFX071'.$a)
                ->setDateOfSignature('2013-08-03')
                ->setDirectDebitInvoice(++$a));
    
    }
    
    //set The payment info
    $paymentInfo->setPaymentInformationIdentification(6222)
        ->setSequenceType('RCUR')
        ->setCreditorAccountIBAN('MD24 AG00 0225 1000 1310 4168')
        ->setCreditorAccountBIC('AABAFI42')->setCreditorName('Amazing SRL')
        ->setCreditorSchemeIdentification('FR07ZZZ519993')
        ->setRequestedCollectionDate('2013-08-06');
    

    //创建 SEPA 文件

    \SEPA\Factory\XMLGeneratorFactory::createXmlGeneratorObject(\SEPA\XMLGenerator::PAIN_008_001_02) ->addXmlMessage( SEPA\Factory\XMLGeneratorFactory::createXMLMessage()->setMessageGroupHeader(

          SEPA\Factory\XMLGeneratorFactory::createXMLGroupHeader()
              ->setMessageIdentification($identificacionFichero = 1)
              ->setInitiatingPartyName($datos['nombreCliente'] = 'test')
              ->setPrivateIdentification($identificador=123)
      )->addMessagePaymentInfo($paymentInfo)
    
    )->save($fileExist = realpath(__DIR__) . '/xml_files/sepa_demo.xml');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多