2

我试图在 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
        (
        )

)

我从上面的消息中找不到任何错误。任何人都可以帮助我。提前致谢 :)

4

1 回答 1

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') );
于 2013-10-21T17:24:22.073 回答