0

我正在尝试将 amazon api 集成到我的网站中,到目前为止,我已经设法让它导航到正确的 xml 部分并将其存储为变量,但是我现在正尝试将此变量插入到我的 mysql 数据库中,它给了我这个错误

注意:未定义变量:致命错误中的 sql_select:在非对象上调用成员函数 query()

我究竟做错了什么?

整个代码

define('INCLUDED', 1);
error_reporting(E_ALL); 
ini_set("display_errors", 1); 
$AWS_ACCESS_KEY_ID = "HIDDENFORPRIVACY";
$AWS_SECRET_ACCESS_KEY = "HIDDENFORPRIVACY";

$base_url = "http://free.apisigning.com/onca/xml?";
$url_params = array('Operation'=>"ItemLookup",'Service'=>"AWSECommerceService",
 'AWSAccessKeyId'=>$AWS_ACCESS_KEY_ID,'AssociateTag'=>"HIDDENFORPRIVACY",
 'Version'=>"2011-08-01",'Availability'=>"Available",'ItemId'=>"0273702440",
 'ItemPage'=>"1",'ResponseGroup'=>"EditorialReview", 'Title'=>"Accounting and Finance for Non-Specialists 5th Edition");

// Add the Timestamp
$url_params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());

// Sort the URL parameters
$url_parts = array();
foreach(array_keys($url_params) as $key)
    $url_parts[] = $key."=".$url_params[$key];
sort($url_parts);

// Construct the string to sign
//$string_to_sign = "GET\nhttp://free.apisigning.com/".implode("&",$url_parts);
//$string_to_sign = str_replace('+','%20',$string_to_sign);
//$string_to_sign = str_replace(':','%3A',$string_to_sign);
//$string_to_sign = str_replace(';',urlencode(';'),$string_to_sign);

// Sign the request
//$signature = hash_hmac("sha256",$string_to_sign,$AWS_SECRET_ACCESS_KEY,TRUE);

// Base64 encode the signature and make it URL safe
//$signature = base64_encode($signature);
//$signature = str_replace('+','%2B',$signature);
//$signature = str_replace('=','%3D',$signature);
//$signature = str_replace(';',urlencode(';'),$string_to_sign);
$url_string = implode("&",$url_parts);
$url = $base_url.$url_string;
//print $url;


$ch = curl_init();                   //this part we set up curl 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$xml_response = curl_exec($ch);
curl_close($ch);
header('Content-type: application/xml');  //specify as xml to not display as one long string
echo $xml_response; 

$xml = new SimpleXMLElement($xml_response);  //time to echo back the correct piece of data

$editorialReview = $xml->Items->Item->EditorialReviews->EditorialReview->Content;

$variable = '<p>Editorial review: '.html_entity_decode($editorialReview).'</p>'."\n";
echo $variable;

$sql_select = mysql_query("INSERT INTO " . DB_PREFIX . "auctions
            (amazon_description) VALUES
            ('" . $variable . "')");
            echo ($sql_select);

这不会发送错误,但 mysql 数据库显示没有变化

4

1 回答 1

1

错误“未定义的变量”表明您尚未初始化对象。

从您打印的代码看来, $sql_select应该是一个包含 select 语句的字符串。

因此,您需要执行以下操作:

$variable = '<p>Editorial review: '.html_entity_decode($editorialReview).'</p>'."\n";
echo $variable;

$sql_select .= "INSERT INTO " . DB_PREFIX . "auctions
            (amazon_description) VALUES
            ('" . $variable . "')";

$DB_object->query($sql_select);

请发布整个代码,以便准确找到解决方案。

于 2012-05-30T01:41:47.303 回答