duai1683 2012-11-14 15:12
浏览 28
已采纳

将类函数插入mysql

I have class that outputs website rank

$urlInfo->getUrlInfo();

This is the alexa amazon aws for rank. the out would be rank of domain. I need to insert the rank into the db but i can't unless i set it to a variable.

what can I do?

i have tried:

 mysql_query("INSERT INTO rank (date, domain, rank) VALUES ('$date','$domain','".$urlInfo->getUrlInfo()."')")

but rank is empty.

this is what the geturlinfo function looks like

    public function getUrlInfo() {
    $queryParams = $this->buildQueryParams();
    $sig = $this->generateSignature($queryParams);
    $url = 'http://' . self::$ServiceHost . '/?' . $queryParams . 
        '&Signature=' . $sig;
    $ret = self::makeRequest($url);
    //echo "
Results for " . $this->site .":

 <br>";
    self::parseResponse($ret);
}

the script then defines the array of the function as result

      public static function parseResponse($response) {
        $xml = new SimpleXMLElement($response,null,false,
                                    'http://awis.amazonaws.com/doc/2005-07-11');
        if($xml->count() && $xml->Response->TrafficHistoryResult->Alexa->count()) {
            $info = $xml->Response->TrafficHistoryResult->Alexa;
            $nice_array = array(

//                 'City'           => $info->ContactInfo->PhysicalAddress->City,
//                 'State'          => $info->ContactInfo->PhysicalAddress->State,
//                 'Postal Code'    => $info->ContactInfo->PhysicalAddress->PostalCode,
//                 'Country'        => $info->ContactInfo->PhysicalAddress->Country,
//                 'Links In Count' => $info->ContentData->LinksInCount,
//                 'Rank'           => $info->TrafficData->Rank,
//                 'Usage'          => $info->TrafficData->UsageStatistics
                    'Rank'          => $info->TrafficHistory->HistoricalData->Data->Rank

            );
        }

                   foreach($nice_array as $k => $v) 
                    {
                        echo $k.': ' . $v ."
 <br>";
                    }

    }

UPDATE: This works. i am now able to put it in a href=XX but still update to mysql shows blanks

    $accessKeyId1 = "XXX";
    $secretAccessKey1 = "XXX";
    $site1 = $_GET['domain'];
    $StartNum1 = $_GET['currentdate']; 

    //$url = $urlInfo->getUrlInfo();
    //echo "URL : ".$url;  

    function Rank($accessKeyId, $secretAccessKey, $site, $StartNum)
    {$urlInfo = new UrlInfo($accessKeyId, $secretAccessKey, $site, $StartNum); $urlInfo->getUrlInfo();}
    echo "test url:<a href='/";
    $test = Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1);

    //$testing = mysql_query("UPDATE rank SET rank = '".Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1)."' WHERE domain = '4shared.com'") or die(mysql_error());
echo $test."'>test</a>";

for the UPDATE i tried Rank($accessKeyId1, $secretAccessKey1, $site1, $StartNum1) and also $test.

any ideas from here?

  • 写回答

1条回答 默认 最新

  • dqab0824 2012-11-15 10:12
    关注

    Try, instead of $urlinfo->geturlinfo() making another prepped statement above named something like $url = $urlinfo->geturlinfo(),then within the statement put '$url' so:

    mysql_query("INSERT INTO rank (date, domain, rank) VALUES ('$date','$domain','$url')");
    

    i think the main problem you are having is the quotation marks, it is splitting the statement into two parts which means the statement isn't complete (don't quote me on that)

    finally do you actually have a table called rank? because it sounds like you're calling it a column/ row.

    I'm only working through my own thought process, I hope this works/ helps =]


    in the comments i was saying that you should do is this->

    $rank = $this->url->getNewValue();
    $url = $this->$rank->getUrlInfo();
    
    mysql_query("INSERT INTO rank (date, domain, rank) VALUES ('$date','$domain','$url')");
    



    Although i would have a look at the link below about SQL Injection it will help protect your application from Hackers.

    SQL Injection: Information
    SQL Injection: Prevention

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?