【发布时间】:2014-02-17 16:43:09
【问题描述】:
我正在开发一个自定义 prestashop 模块,该模块从另一个数据库(外部数据库)检索数据,然后将数据插入 prestashop 数据库。我制作了一个 php 文件,它从外部数据库中检索数据并保存到会话变量中。
我从那个 php 文件中得到了这个数组:
[0] => Array
(
[0] => 1
[productid] => 1
[1] => 0
[parent] => 0
[2] => 0
[3] => iPod Shuffle
[prodname] => iPod Shuffle
这是它的代码:`FILE)。 "/settings.inc.php");
//database 1
//$data = array();
$conn = @mysql_connect($GLOBALS['VCS_CFG']["dbServer"],$GLOBALS['VCS_CFG']["dbUser"], $GLOBALS['VCS_CFG']["dbPass"]);
if ($conn){
if (mysql_select_db($GLOBALS['VCS_CFG']["dbDatabase"])) {
$SQL = "SELECT * FROM vc_products";
$q = mysql_query($SQL);
while($row = mysql_fetch_array($q))
{
$json_output[] = $row;
$_SESSION['myData'] = $json_output;
}
//echo json_encode($json_output);
print_r($_SESSION['myData']);
}
mysql_close($conn);
}
`
我试图在表 ps_order_detail 表的 product_name 行中插入行 prodname。现在我正在制作 prestashop 模块,它将将该数据插入 Prestashop 数据库。这是我的代码:
这是我模块的数据插入代码:
<?php
if (!defined('_PS_VERSION_'))
exit;
include 'test.php';
class PrestaBridge extends Module
{
public function __construct()
{
$this->name = 'PrestaBridge';
$this->tab = 'Front';
$this->version = 1.5;
$this->author = 'Sergio Kagiema';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('PrestaBridge');
$this->description = $this->l('A module for transferring data from Vcart to Prestashop!');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (!Configuration::get('PrestaBridge'))
$this->warning = $this->l('No name provided');
}
//INSTALL TOY MODULE
public function install()
{
$parent_tab = new Tab();
foreach (Language::getLanguages(true) as $lang)
$parent_tab->name [$lang['id_lang']] = 'PrestaBridge';
$parent_tab->class_name = 'BridgePage';
$parent_tab->id_parent = 0;
$parent_tab->module = $this->name;
$parent_tab->add();
if (!parent::install()
|| !$this->installModuleTab('BridgePage', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'PrestaBridge'), $parent_tab->id)
)
return false;
return true;
}
//UNISTALL TOY MODULE
public function uninstall()
{
if (!parent::uninstall()
|| !$this->uninstallModuleTab('BridgePage')
)
return false;
return true;
}
private function installModuleTab($tabClass, $tabName, $idTabParent)
{
$idTab = Tab::getIdFromClassName($idTabParent);
$idTab = $idTabParent;
$pass = true ;
@copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$tabClass.'.gif');
$tab = new Tab();
$tab->name = $tabName;
$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = $idTab;
$pass = $tab->save();
return($pass);
}
private function uninstallModuleTab($tabClass)
{
$pass = true ;
@unlink(_PS_IMG_DIR_.'t/'.$tabClass.'.gif');
$idTab = Tab::getIdFromClassName($tabClass);
if($idTab != 0)
{
$tab = new Tab($idTab);
$pass = $tab->delete();
}
return($pass);
}
public function getContent() {
$this->_html = '<h2>'.$this->displayName.'</h2>';
if (Tools::isSubmit('submit')) {
$sql = 'INSERT INTO '._DB_PREFIX_.'order_detail(product_id, product_name) VALUES';
$valuesArr = array();
if ($data = Db::getInstance()->Execute($sql))
foreach ($data as $row){
$product_id = (int) $row['productid'];
$product_name = $row['prodname'];
$valuesArr[] = "('$product_id', '$product_name')";
}
$sql .= implode(',', $valuesArr);
$this->_displayForm();
return $this->_html;
}
}
private function _displayForm() {
$this->_html .= '<div class="clear"></div>';
$this->_html .= '<div class="bridge" id="bridge">';
$this->_html .= '<form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="test">';
$this->_html .= '<input type="text" name="username" id="username"/>';
$this->_html .= '<input type="text" name="password" id="password"/>';
$this->_html .= '<button id="myButton" onclick="myfunc()" type="submit">Transfer Data</button>';
$this->_html .= '</div>';
}
}
?>
你能帮帮我吗?
【问题讨论】:
-
我们在谈论什么版本?你想在哪里连接?模块 ?在 prestashop 中,有一种从数据库中添加/选择/更新/删除的严格方法。请回答我的问题,我会帮助你
-
这是关于 Prestashop 1.5 的。我正在制作一个将数据插入 Prestashop 数据库的模块。所以,我正在尝试使用 ftp 连接到我的数据库。
标签: php sql prestashop