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

)

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

最佳答案

老实说,我没用过乔姆拉这么多。然而,根据所提供的信息(并且在查看了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') );

关于php - Mysql UPDATE查询在Joomla中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19500696/

10-13 02:59