2013-10-21 68 views
2

我正試圖更新Joomla中的會話數據庫。我正在嘗試這個代碼:Mysql更新查詢不在Joomla工作

$query2 = $db->getQuery(true); 
      $query2->update($db->quoteName('#__session')) 
      ->set($db->quoteName('guest') . ' = 0') 
      ->set($db->quoteName('userid') . ' = ' . $query['0']) 
      ->where($db->quoteName('session_id') . ' = 5f1d77847561d448c88fd5f7009c156f'); 

      // Try to update the session data in the database table. 
      $db->setQuery($query2); 
      $db->execute(); 

但它不工作。但是我還是打印查詢&它是這樣的:

JDatabaseMySQLi Object 
(
    [name] => mysqli 
    [nameQuote:protected] => ` 
    [nullDate:protected] => 0000-00-00 00:00:00 
    [dbMinimum:protected] => 5.0.4 
    [_database:JDatabase:private] => joomla 
    [connection:protected] => mysqli Object 
     (
      [affected_rows] => 1 
      [client_info] => 5.5.31 
      [client_version] => 50531 
      [connect_errno] => 0 
      [connect_error] => 
      [errno] => 0 
      [error] => 
      [error_list] => Array 
       (
       ) 

      [field_count] => 14 
      [host_info] => Localhost via UNIX socket 
      [info] => 
      [insert_id] => 0 
      [server_info] => 5.5.31-0ubuntu0.13.04.1 
      [server_version] => 50531 
      [stat] => Uptime: 14158 Threads: 2 Questions: 9760 Slow queries: 0 Opens: 5736 Flush tables: 1 Open tables: 400 Queries per second avg: 0.689 
      [sqlstate] => 00000 
      [protocol_version] => 10 
      [thread_id] => 1030 
      [warning_count] => 0 
     ) 

    [count:protected] => 0 
    [cursor:protected] => mysqli_result Object 
<br /> 
<b>Warning</b>: print_r(): Couldn't fetch mysqli_result in <b>/var/www/app/user_access.php</b> on line <b>63</b><br /> 
<br /> 
<b>Warning</b>: print_r(): Couldn't fetch mysqli_result in <b>/var/www/app/user_access.php</b> on line <b>63</b><br /> 
<br /> 
<b>Warning</b>: print_r(): Property access is not allowed yet in <b>/var/www/app/user_access.php</b> on line <b>63</b><br /> 
<br /> 
<b>Warning</b>: print_r(): Couldn't fetch mysqli_result in <b>/var/www/app/user_access.php</b> on line <b>63</b><br /> 
<br /> 
<b>Warning</b>: print_r(): Property access is not allowed yet in <b>/var/www/app/user_access.php</b> on line <b>63</b><br /> 
     (
      [current_field] => 
      [field_count] => 
      [lengths] => 
      [num_rows] => 
      [type] => 
     ) 

    [debug:protected] => 
    [limit:protected] => 0 
    [log:protected] => Array 
     (
     ) 

    [offset:protected] => 0 
    [sql:protected] => JDatabaseQueryMySQLi Object 
     (
      [db:protected] => JDatabaseMySQLi Object 
*RECURSION* 
      [type:protected] => update 
      [element:protected] => 
      [select:protected] => 
      [delete:protected] => 
      [update:protected] => JDatabaseQueryElement Object 
       (
        [name:protected] => UPDATE 
        [elements:protected] => Array 
         (
          [0] => `#__session` 
         ) 

        [glue:protected] => , 
       ) 

      [insert:protected] => 
      [from:protected] => 
      [join:protected] => 
      [set:protected] => JDatabaseQueryElement Object 
       (
        [name:protected] => SET 
        [elements:protected] => Array 
         (
          [0] => `guest` = 0 
          [1] => `userid` = 758 
         ) 

        [glue:protected] => 
    , 
       ) 

      [where:protected] => JDatabaseQueryElement Object 
       (
        [name:protected] => WHERE 
        [elements:protected] => Array 
         (
          [0] => `session_id` = 5f1d77847561d448c88fd5f7009c156f 
         ) 

        [glue:protected] => AND 
       ) 

      [group:protected] => 
      [having:protected] => 
      [columns:protected] => 
      [values:protected] => 
      [order:protected] => 
      [union:protected] => 
      [autoIncrementField:protected] => 
     ) 

    [tablePrefix:protected] => rjx4y_ 
    [utf:protected] => 1 
    [errorNum:protected] => 0 
    [errorMsg:protected] => 
    [hasQuoted:protected] => 
    [quoted:protected] => Array 
     (
     ) 

) 

我無法從上面的消息發現任何錯誤。任何人都可以幫助我。在此先感謝:)

回答

0

我會誠實 - 我沒有使用Joomla鉅額。然而,根據提供的信息(以及在瀏覽一些Joomla源代碼之後),我懷疑這是與您的代碼的$db->quoteName('session_id') . ' = 5f1d77847561d448c88fd5f7009c156f'部分有關。

從它看起來,因爲你提供的條件作爲一個字符串,值不一定逃脫。它可以很好地處理數字 - 但不能與字符串一起使用。

您需要使用它之前逃脫會話字符串:

$query2 = $db->getQuery(true); 
$query2->update($db->quoteName('#__session')) 
     ->set($db->quoteName('guest') . ' = 0') 
     ->set($db->quoteName('userid') . ' = ' . $query['0']) 
     ->where($db->quoteName('session_id') . ' = ' . $db->escape('5f1d77847561d448c88fd5f7009c156f')); 
+0

感謝您的回覆garbetjie。但對不起,它不工作。實際上,查詢執行時沒有任何錯誤。但由於某些原因,它並未更新數據庫表。我從終端的命令行嘗試它,它正在工作,但不是這樣:( – jibon57

+0

啊。我不知道它在另一種情況下工作。根據[文檔](http://api.joomla.org /Joomla-Platform/Database/JDatabaseDriver.html#var$debug),似乎你可以將'$ db-> debug'設置爲'true',並且可以啓用調試。我假設你'已經嘗試過了嗎? – garbetjie

+0

再次感謝..我只是試圖顯示錯誤:$ db - > $ errorMsg();&得到這個錯誤致命錯誤:方法名稱必須是字符串/var/www/app/user_access.php on line 66 ... – jibon57