doubanduo7620 2014-08-22 07:18
浏览 11
已采纳

“×”字符破坏MySQL记录

The "×" symbol (not a little x), I believe this is the multiplication symbol, is breaking MySQL records.

The problem is that whenever I try to retrieve a record that has this symbol "×" the record returns as blank.

I am using PHP and WAMP server by the way.

The collation is latin1_swedish_ci. However, changing collations didn't seem to fix the problem. The mysql version is 5.6.17 Here is my function that gets the records from the table and saves it to an object:

public function assign() {
    $SQL = "SELECT * FROM " . $this->tb . " ORDER BY " . $this->order;
    $this->tb_handle = mysqli_query($this->db_handle,$SQL);

    $this->rowNumber = mysqli_num_rows($this->tb_handle);

    //this creates arrays from records given even if the table is empty
    //this is to prevent errors
    if ($this->rowNumber === 0) {
        foreach ($this->records as $record) {
            $this->{$record} = array();
        } 
    } else {
        $i = 0;        
        while ( $db_field = mysqli_fetch_assoc($this->tb_handle) ) {
            foreach ($this->records as $record) {
                $this->{$record}[$i] = $db_field[$record];
                $this->{$record}[$i] = htmlspecialchars($this->{$record}[$i]);
            }            
            $i++;
        }
    }
}

This works for anything that does not have the "×" symbol. i don't know why that symbol should cause the entire record to return as blank.

  • 写回答

1条回答 默认 最新

  • doulang2311 2014-08-22 07:22
    关注

    I see you use the htmlspecialchars until PHP 5.4 the internal encoding is UTF-8. So if you have a record with iso data and you put it in htmlspecialchars you get no result.

    In this case you have to set the encoding to iso-8859-1 for example.

    To solve the problem you can define an encoding

    htmlspecialchars($value, ENT_QUOTES, "ISO-8859-1");

    This will fix symbols showing incorrectly:

    mb_convert_encoding($value, "UTF-8");

    I think this could be your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数