Php 执行从Prestashop到外部数据库的查询

Php 执行从Prestashop到外部数据库的查询,php,mysql,smarty,prestashop,prestashop-1.6,Php,Mysql,Smarty,Prestashop,Prestashop 1.6,我正在尝试从Prestashop连接到外部数据库(ERP),以从中获取订单历史记录 我克隆了历史控制器并将其命名为“residui” 我创建了包含以下内容的ResiduiController.php: class ResiduiControllerCore extends FrontController { public $auth = true; public $php_self = 'residui'; public $authRedirection = 'residui'; public

我正在尝试从Prestashop连接到外部数据库(ERP),以从中获取订单历史记录

我克隆了历史控制器并将其命名为“residui

我创建了包含以下内容的ResiduiController.php

class ResiduiControllerCore extends FrontController {
public $auth = true;
public $php_self = 'residui';
public $authRedirection = 'residui';
public $ssl = true;

public function setMedia() {
    parent::setMedia();
    $this->addCSS(array(
        _THEME_CSS_DIR_.'residui.css',
    ));
    $this->addJS(array(
        _THEME_JS_DIR_.'history.js',
        _THEME_JS_DIR_.'tools.js' // retro compat themes 1.5
    ));
    $this->addJqueryPlugin('footable');
    $this->addJqueryPlugin('footable-sort');
    $this->addJqueryPlugin('scrollTo'); } 

public function initContent() {
    parent::initContent();

    $residui = Order::getCustomerResidui($this->context->customer->id);

    $this->context->smarty->assign(array(
        'residui' => $residui
    ));

    $this->setTemplate(_PS_THEME_DIR_.'residui.tpl');   }   }
我已经按顺序插入了类getCustomerResidui。php:

public static function getCustomerResidui($id_customer, $showHiddenStatus = false, Context $context = null) {
    if (!$context)
        $context = Context::getContext();
    $evadi = 'S';
    $stato = 'GENERATO';
    $resi = Db::getFromGazie()->executeS("
    SELECT *
    FROM "._GAZ_PREFIX_."tesbro
    WHERE id_cli_presta = '".(int)$id_customer."' AND status =  '".$stato."'
    ORDER BY id_tes DESC");
    if (!$resi)
        return array();

    foreach ($resi as $key => $val) {
        $resi2 = Db::getFromGazie()->executeS("
            SELECT *
            FROM "._GAZ_PREFIX_."rigbro
            WHERE id_doc = '".$val['numdoc']."' AND evadi <> '".$evadi."'
            ORDER BY codart DESC LIMIT 1");

        if ($resi2)
            $resi[$key] = array_merge($resi[$key], $resi2[0]);  }
    return $resi;   }   }
<div class="block-center" id="block-history">
    <table id="order-list" class="table table-bordered footab">
        <thead>
            <tr>
                <th class="first_item" data-sort-ignore="true">{l s='Order reference'}</th>
                <th class="item">{l s='Date'}</th>

            </tr>
        </thead>
        <tbody>
            {foreach from=$residui item=residuo name=myLoop}
                <tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{/if}">
                    <td class="history_link bold">
                        <p class="color-myaccount">
                            {$residuo['numdoc']}
                        </p>
                    </td>
                    <td class="history_date bold">
                    {$residuo['datemi']}
                    </td>

                </tr>
            {/foreach}
        </tbody>
    </table>
    <div id="block-order-detail" class="unvisible">&nbsp;</div>
模板,residui.tpl:

public static function getCustomerResidui($id_customer, $showHiddenStatus = false, Context $context = null) {
    if (!$context)
        $context = Context::getContext();
    $evadi = 'S';
    $stato = 'GENERATO';
    $resi = Db::getFromGazie()->executeS("
    SELECT *
    FROM "._GAZ_PREFIX_."tesbro
    WHERE id_cli_presta = '".(int)$id_customer."' AND status =  '".$stato."'
    ORDER BY id_tes DESC");
    if (!$resi)
        return array();

    foreach ($resi as $key => $val) {
        $resi2 = Db::getFromGazie()->executeS("
            SELECT *
            FROM "._GAZ_PREFIX_."rigbro
            WHERE id_doc = '".$val['numdoc']."' AND evadi <> '".$evadi."'
            ORDER BY codart DESC LIMIT 1");

        if ($resi2)
            $resi[$key] = array_merge($resi[$key], $resi2[0]);  }
    return $resi;   }   }
<div class="block-center" id="block-history">
    <table id="order-list" class="table table-bordered footab">
        <thead>
            <tr>
                <th class="first_item" data-sort-ignore="true">{l s='Order reference'}</th>
                <th class="item">{l s='Date'}</th>

            </tr>
        </thead>
        <tbody>
            {foreach from=$residui item=residuo name=myLoop}
                <tr class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{/if}">
                    <td class="history_link bold">
                        <p class="color-myaccount">
                            {$residuo['numdoc']}
                        </p>
                    </td>
                    <td class="history_date bold">
                    {$residuo['datemi']}
                    </td>

                </tr>
            {/foreach}
        </tbody>
    </table>
    <div id="block-order-detail" class="unvisible">&nbsp;</div>

{l s='Order reference'}
{l s='Date'}
{foreach from=$residui item=residuo name=myLoop}

{$residuo['numdoc']}

{$residuo['datemi']} {/foreach}

问题是,我没有显示任何行(我还在PhpMyAdmin中手动测试了查询)

我试了几个小时,但我看不出错误(我肯定我犯了一个或多个)

你能告诉我一些事情吗?谢谢…

明白了

首先,感谢Sergii p,它建议了我不知道的模式开发

问题是它总是试图在同一个数据库上执行查询。为了解决这个问题,我在前缀之前添加了_GAZ_NAME_uu,如下所示:

public static function getCustomerResidui($id_customer, $showHiddenStatus = false, Context $context = null)
{
    if (!$context)
        $context = Context::getContext();
    $evadi = 'S';
    $stato = 'GENERATO';
    $resi = Db::getFromGazie()->executeS("
    SELECT *
    FROM "._GAZ_NAME_."."._GAZ_PREFIX_."tesbro
    WHERE id_cli_presta = '".(int)$id_customer."' AND status =  '".$stato."'
    ORDER BY id_tes DESC");
    if (!$resi)
        return array();

    foreach ($resi as $key => $val)
    {
        $resi2 = Db::getFromGazie()->executeS("
            SELECT *
            FROM "._GAZ_NAME_."."._GAZ_PREFIX_."rigbro
            WHERE id_doc = '".$val['numdoc']."' AND evadi <> '".$evadi."'
            ORDER BY codart DESC LIMIT 1");

        if ($resi2)
            $resi[$key] = array_merge($resi[$key], $resi2[0]);

    }
    return $resi;
}
公共静态函数getCustomerResidui($id\u customer,$showHiddenStatus=false,Context$Context=null)
{
如果(!$context)
$context=context::getContext();
$evadi='S';
$stato='GENERATO';
$resi=Db::getFromGazie()->执行(“
挑选*
来自“..\u GAZ.\u NAME...”.\u GAZ.\u前缀.”tesbro
其中id_cli_presta='”(int)$id_customer.”和status='“$stato.”
按id订购(“描述”);
如果(!$resi)
返回数组();
foreach($resi as$key=>$val)
{
$resi2=Db::getFromGazie()->执行(“
挑选*
来自“...\u GAZ.\u NAME...”.\u GAZ.\u前缀.”rigbro
其中id_doc=“$val['numdoc']”.“'AND evadi”“。$evadi.”
按codart DESC LIMIT 1)订购;
如果(2美元)
$resi[$key]=数组合并($resi[$key],$resi2[0]);
}
返回$resi;
}

瞧,一切都很好

好的,一步一步地,你有调试吗<代码>getFromGazie返回正确的实例<代码>变量转储(订单::getCustomerResidui($this->context->customer->id))结果?同样在
config/defines.inc.php
set
define中(“PS”模式“DEV”模式),true)
直接在第页上查看错误谢谢您的回答。我不知道PS_DEV_模式,现在我尝试更改
var_dump(Order::getCustomerResidui($this->context->customer->id))使用
$this->context->smarty->assign(数组('residui'=>Db::getFromGazie()->执行(“从”.\u GAZ\u PREFIX\u.tesbro中选择*”,其中id\u cli\u presta=“$id\u customer.”和status='GENERATO'按id\u tes DESC生成订单”)并且结果是一个空行。问题是getFromGazie试图从Prestashop的DB执行查询…我不明白为什么!以下是调试结果:表“vhsxxx_uuzzzz.yyyyy.gaz_001tesbro”不存在,但getFromGazie_zz_001;服务器是vhsxxx_zzzzzz.gaz_001tesbro