簡體   English   中英

在MySQL中通過PHP查詢

[英]Query via php in MYSQL

我嘗試將查詢發送到我的mysql,但是在兩個小時內確實無法解決問題:S

 foreach ($ga->getResults() as $result) {

        $ga->requestReportData($result->getProfileId(), array('eventCategory', 'eventAction'), array('totalEvents'), $sort_metric = null, $filter = 'eventAction==InitPlayer', $start_date = $startDate, $end_date = $startDate);
        foreach ($ga->getResults() as $result2) {
            $key = array_search($result2->geteventCategory(), $arrEventCategory);
            $key2 = array_search($result, $arrProfiles);
            echo $key . " ||  <b>" . $key2 . "</b>";

            echo $result2->gettotalEvents();

            $mysql->query("insert into initplayer values(" . $key2 . ",'" . $result2->gettotalEvents() . "','" . $startDate . "'," . $key . ")");
            echo "insert into initplayer values(" . $key2 . ",'" . $result2->gettotalEvents() . "','" . $startDate . "'," . $key . "";
        }
    }

這是我的代碼,頁面給出該行錯誤:

 $mysql->query("insert into initplayer values(" . $key2 . ",'" . $result2->gettotalEvents() . "','" . $startDate . "'," . $key . ")");

錯誤是:您的SQL語法有錯誤; 檢查與您的MySQL服務器版本相對應的手冊,以在第1行的')'附近使用正確的語法

呈現查詢: 在此處輸入圖片說明

首先,您能否給出在循環的最后一行得到回顯的查詢? 其次,看起來正在運行的查詢和正在打印的查詢有所不同。 發送到MySQL的查詢最后有一個額外的括號。 如果要出於調試目的而回顯查詢,請引入一個變量,以便對正在運行的確切查詢進行調試:

$rendered_query = "insert into initplayer values(" . $key2 . ",'" . $result2->gettotalEvents() . "','" . $startDate . "'," . $key . ")";

$mysql->query( $rendered_query );
echo $rendered_query;

一旦發布回顯的結果,我將更新此答案,因為我無法調試$result2->gettotalEvents()類的方法的輸出

在某個時候,您的$ key或$ key2可能為FALSE(在數組中找不到),並且您可能會得到類似以下查詢:

insert into  initplayer values(FALSE,'something', 'something'....., 'something',FALSE);

這會導致mysql語法錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM