Mysql UPDATE查询无法在Joomla中运行

时间:2013-10-21 17:11:33

标签: php mysql joomla

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

)

我无法从上述消息中找到任何错误。任何人都可以帮助我。在此先感谢:)

1 个答案:

答案 0 :(得分: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') );