gpt4 book ai didi

php - 如何使用来自 xml-rpc 的数据更新数据库表?

转载 作者:行者123 更新时间:2023-11-29 00:59:13 25 4
gpt4 key购买 nike

我想对您的任何回复表示感谢。非常感谢您的帮助。

更新 我刚刚在这个网站上看到有人提到了 xml 数据类型和存储过程。现在我认为搜索 xml-rpc 和更新数据库是不够的。我正在寻找如何使用 xml 数据更新数据库。但如果你对我下面的问题仍有想法,我将不胜感激。

我已经通过 xml-rpc 使用从远程服务器提取的数据来更新数据库表的可能性以及如何使用 Google 搜索并搜索了该站点,但我找不到关于如何做这样的事情的任何信息。我确实在 xml-rpc 上找到了大量有用的信息(我是全新的)并且更新数据库表的 SQL 命令非常简单。但是我究竟如何使用我通过 xml-rpc 获取的数据来更新表呢?

我想是因为我可能没有完全理解xml-rpc。我有一个购物车,我现在想做的就是从我的供应商那里提取库存水平。当用户点击指向产品的链接时,我需要获取实时库存水平并将这些库存水平数字插入到我的特定产品的产品库存表中(因此它是即时的)。

我看了一下 php 文件,其中购物车脚本看起来从数据库中获取了商品的库存水平。似乎我会在抓取之前添加两件事。 1. 通过 sku 获取库存水平的 xml-rpc 调用和 2. 将数据插入数据库的 SQL 更新命令。

但是一旦我执行了 xml-rpc 调用并且它返回了库存水平,这些数据去哪里了?根据我的阅读,这些数据似乎是通过某种打印方式向用户显示的,或者直接向网络浏览器显示结果。但是我不需要这样做,而是需要将这些数据移动到数据库表中。

有什么想法吗?这可能吗?

这是我为尝试获取库存水平并更新表格而编辑的函数:我已将这两个部分添加到现有函数中 - //按 sku 从供应商处获取库存水平, //按sku更新库存表

  /**
* Show the inventory management quick view on the manage products page if inventory tracking is on for a product
*
* @return void
**/
private function GetInventoryLevels()
{
$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('products');

if(isset($_REQUEST['p']) && isset($_REQUEST['i']) && isset($_REQUEST['v']) && isset($_REQUEST['t'])) {
$prodId = (int)$_REQUEST['p'];
$invType = (int)$_REQUEST['i'];
$variationId = (int)$_REQUEST['v'];
$combinations = array();

// First determine if inventory tracking is by product or by option
if ($invType == 1) {
**// Grab inventory level by sku from supplier**
$server_url = "http://gg.com/ttt/webservices/index.php";
$prodcurrentinv = "";
if (function_exists('xmlrpc_encode_request')) {
$request = xmlrpc_encode_request("catalog.getStockQuantity(sku)", array($prodcurrentinv));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));
$file = file_get_contents($server_url, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
print '<pre>';
print_r($response);
print '</pre>';
}
} else {
print '<div style="color:red;">Sorry, you don\'t seem to have the xmlrpc module compiled in.</div>';
}
print '<hr/>';
require_once 'XML/RPC2/Client.php';
// since we're using a 'catalog' function, we need to make sure it prefixes the function
// name when it's called on the server. (The XML_RPC2 docs suggest that you could use
// 'catalog.getStockQuantity(sku)' as the class function name, but that's not correct.
$options = array(
'prefix' => "catalog."
);
$client = XML_RPC2_Client::create($server_url, $options);
$result = $client->getStockQuantity(sku)($prodcurrentinv);
print '<pre>';
print_r($result);
print '</pre>';
print '<hr/>';
**// Update inventory table by sku**
$query = sprintf("update prodcurrentinv from [|PREFIX|]products where productcode='%d'",)
// Simply query the products table for current and low stock levels
$query = sprintf("select prodcurrentinv, prodlowinv from [|PREFIX|]products where productid='%d'", $GLOBALS['ISC_CLASS_DB']->Quote($prodId));
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

if($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
printf("<b style='font-size:13px; padding-bottom:5px'>%s</strong>", GetLang("UpdateInventoryLevels"));
echo "<table border='0'>";
echo "<tr>";
echo "<td valign='top'><img src='images/nodejoin.gif' style='padding-top:5px' /></td>";
printf("<td>%s:</td>", GetLang("CurrentStock"));
printf("<td><input type='text' size='3' value='%d' name='stock_level_%d' id='stock_level_%d' /></td>", $row['prodcurrentinv'], $prodId, $prodId);
echo "</tr>";
echo "<tr>";
echo "<td>";
printf("<td>%s:</td>", GetLang("LowStockLevel"));
printf("<td><input type='text' size='3' value='%d' name='stock_level_notify_%d' id='stock_level_notify_%d' /></td>", $row['prodlowinv'], $prodId, $prodId);
echo "</tr>";
echo "</table>";
printf("<input class='StockButton' type='button' value='%s' onclick='UpdateStockLevel(%d, 0)' style='margin-left:110px' />&nbsp; <img src='images/ajax-blank.gif' id='loading%d' />", GetLang("Save"), $prodId, $prodId);
}
} else {
$optionIds = array();

// Fetch out the variation combinations for this product
$query = "SELECT * FROM [|PREFIX|]product_variation_combinations WHERE vcproductid='".$prodId."'";
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
while($combination = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$combinations[] = $combination;
$optionIds = array_merge($optionIds, explode(",", $combination['vcoptionids']));
}

$optionIds = array_unique($optionIds);

// Now fetch out the options we need to get
if(!empty($optionIds)) {
$optionIds = implode(",", $optionIds);
// Get the combination options
$variations = array();
$query = "SELECT * FROM [|PREFIX|]product_variation_options WHERE voptionid IN (".$optionIds.")";
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
while($variation = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$variations[$variation['voptionid']] = array($variation['voname'], $variation['vovalue']);
}
}

printf("<b style='font-size:13px'>%s</strong><div style='padding:20px 20px 0px 20px'>", GetLang("UpdateInventoryLevels"));

foreach($combinations as $row) {
$output = "";
$options = explode(",", $row['vcoptionids']);

foreach($options as $option) {
$output .= isc_html_escape($variations[$option][0]) . ": " . isc_html_escape($variations[$option][1]) . ", ";
}

$output = trim($output, ', ');
echo "<strong><em>" . $output . "</em></strong>";
echo "<br />";
echo "<table border='0' style='padding-bottom:10px'>";
echo "<tr>";
echo "<td valign='top'><img src='images/nodejoin.gif' style='padding-top:5px' /></td>";
printf("<td>%s:</td>", GetLang("CurrentStock"));
printf("<td><input type='text' size='3' value='%d' name='stock_level_%d_%d' id='stock_level_%d_%d' /></td>", $row['vcstock'], $prodId, $row['combinationid'], $prodId, $row['combinationid']);
echo "</tr>";
echo "<tr>";
echo "<td>";
printf("<td>%s:</td>", GetLang("LowStockLevel"));
printf("<td><input type='text' size='3' value='%d' name='stock_level_%d_%d' id='stock_level_notify_%d_%d' /></td>", $row['vclowstock'], $prodId, $row['combinationid'], $prodId, $row['combinationid']);
echo "</tr>";
echo "</table>";
}

echo "</div>";
printf("<input class='StockButton' type='button' value='%s' onclick='UpdateStockLevel(%d, 1)' style='margin-left:130px' />&nbsp; <img src='images/ajax-blank.gif' id='loading%d' />", GetLang('Save'), $prodId, $prodId);
}
}
}

最佳答案

经过反复试验,我弄明白了。我会分享以防其他人有同样的问题。我编写的这段代码根据产品 ID 从数据库中获取 sku 编号。然后它通过 xml-rpc 根据 sku 向供应商请求库存水平,得到响应,然后更新数据库中产品 id 的当前库存水平。

                                //Grab the stock level of the item from supplier server
$query = sprintf("SELECT prodcode FROM [|PREFIX|]products where productid='%d'",
$GLOBALS['ISC_CLASS_DB']->Quote($prodId));
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
$product_sku = mysql_fetch_row($result);
$product_sku2 = $product_sku[0];

$server_url = "http://m.com/fvg/webservices/index.php";

$request = xmlrpc_encode_request("catalog.getStockQuantity", array($product_sku2));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));
$file = file_get_contents($server_url, false, $context);
$response = xmlrpc_decode($file);

$query = sprintf("UPDATE [|PREFIX|]products SET prodcurrentinv='$response' where productid='%d'", $GLOBALS['ISC_CLASS_DB']->Quote($prodId));
$result = $GLOBALS['ISC_CLASS_DB']->Query($query);

关于php - 如何使用来自 xml-rpc 的数据更新数据库表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4500401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com