【问题标题】:Database Error No. 1231 on 000webhost website000webhost 网站上的数据库错误编号 1231
【发布时间】:2019-08-14 16:39:48
【问题描述】:

我的网站自一年前上传以来一直运行良好。但几天前我突然在我的 000webhost.com 网站上收到错误消息 1231。当我打开我的网站或浏览它之后,错误就出现了。有人可以帮忙吗?有人遇到过这个错误吗?可能是什么原因?以及如何解决?

我认为我可以通过将我的 codeigniter 3.1.7 更新到最新版本 3.1.10 来修复它,但它没有帮助。我将 php 版本从 7.2 更改为 7.0,然后更改为 5.6,也没有任何区别。

libraries/Session/drivers/Session_database_driver.php 和 mysql_driver.php

    /**
     * Validate ID
     *
     * Checks whether a session ID record exists server-side,
     * to enforce session.use_strict_mode.
     *
     * @param   string  $id
     * @return  bool
     */
    public function validateSessionId($id)
    {
        // Prevent previous QB calls from messing with our queries
        $this->_db->reset_query();

        $this->_db->select('1')->from($this->_config['save_path'])->where('id', $id);
        empty($this->_config['match_ip']) OR $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']);
        $result = $this->_db->get();
        empty($result) OR $result = $result->row();

        return ! empty($result);
    }

/**
 * Database connection
 *
 * @param   bool    $persistent
 * @return  object
 */
public function db_connect($persistent = FALSE)
{
    // Do we have a socket path?
    if ($this->hostname[0] === '/')
    {
        $hostname = NULL;
        $port = NULL;
        $socket = $this->hostname;
    }
    else
    {
        $hostname = ($persistent === TRUE)
            ? 'p:'.$this->hostname : $this->hostname;
        $port = empty($this->port) ? NULL : $this->port;
        $socket = NULL;
    }

    $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
    $this->_mysqli = mysqli_init();

    $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);

    if (isset($this->stricton))
    {
        if ($this->stricton)
        {
            $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
        }
        else
        {
            $this->_mysqli->options(MYSQLI_INIT_COMMAND,
                'SET SESSION sql_mode =
                REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                @@sql_mode,
                "STRICT_ALL_TABLES,", ""),
                ",STRICT_ALL_TABLES", ""),
                "STRICT_ALL_TABLES", ""),
                "STRICT_TRANS_TABLES,", ""),
                ",STRICT_TRANS_TABLES", ""),
                "STRICT_TRANS_TABLES", "")'
            );
        }
    }

发生数据库错误 错误号:1231

变量‘sql_mode’不能设置为‘REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@@sql_mode’的值】

从 ci_sessions 中选择 1,其中 id = ‘9mk3avf3kaocstm4rrcappec902q2msi’ AND ip_address = ‘x.x.x.x’

文件名:libraries/Session/drivers/Session_database_driver.php

行号:363

【问题讨论】:

  • @aynber iam 更想在阅读代码后评论 不以严格模式运行 MySQL 总是自找麻烦..
  • 我应该改变什么?
  • @RaymondNijland 非常正确。我不知道 CodeIgnitor 有什么设置,但调整设置会有所帮助。我建议从空字符串开始,然后一次将每个设置添加回去,看看有什么效果
  • 检查$this->stricton 的设置位置并将其设置为true(很可能是database.php),就像@aynber 建议的那样。或者编辑codeigniter 代码以便它执行SET SESSION sql_mode = (REPLACE ...) 我假设也应该做到这一点,但理想情况下你不应该编辑框架代码..

标签: php mysql database codeigniter


【解决方案1】:

打开文件applications/config/database.php 将变量 stricton 更改为 TRUE

'stricton' => TRUE,

【讨论】:

  • 是的,谢谢,我做到了。起初收到更多错误消息,我设法修复了第一个错误消息,而其他所有错误消息都消失了,现在一切正常了!!!谢谢大家!!!
猜你喜欢
  • 2012-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-18
  • 1970-01-01
  • 2020-12-19
  • 2014-02-11
  • 2010-11-22
相关资源
最近更新 更多