dongtigai3875 2018-02-01 19:36
浏览 108

PHP - 在mysql varchar中插入小时的字符串末尾添加NULL

I have a really strange (for me) problem. I have a Mysql db where i store opening hours of a store: This is the table stucture

#   Nome        Tipo            Codifica caratteri  </br>
1   id          int(11)         No</br>
2   store_slug  varchar(50)     utf8_unicode_ci </br>
3   dow         tinyint(4)      No</br>
4   type        varchar(2)      utf8_unicode_ci </br>
5   open        varchar(10)     utf8_unicode_ci</br>    
6   close       varchar(10)     utf8_unicode_ci </br>
7   extra_text  varchar(50)     utf8_unicode_ci</br>

I get time as input in a one php file and another php file insert that input data to the database.The problem is here:

<?php $open_d = $hours[$i]["d"]["o"];
      $close_d =  $hours[$i]["d"]["c"];
      $type = "d";
      $sql = "INSERT INTO `".MLS_PREFIX."store_hours`(store_slug,dow,type,open,close) VALUE('$store_slug',$i,'$type','$open_d','$close_d')";
      echo $sql ;
      echo "</br>";
      if($db->query($sql)){ echo "Store saved !"; } else { echo "Some error came up ! "; }

?>

For example Resulting SQL insert for 1 row is :

INSERT INTO `aCr_store_hours`(store_slug,dow,type,open,close) VALUE('haki',1,'d','13:01','15:00')

When I copy and execute this SQL in phpmyadmin all works fine but if i use the PHP script with the same SQL the time in 'open' and 'close' columns will be something like this

enter image description here

Can, please, someone help me with this really strange problem?

Thanks and have a nice day!

Regards

Michele

  • 写回答

2条回答 默认 最新

  • dongnan1899 2018-02-01 19:45
    关注

    You need to escape the colon in your query. Try prefixing all colons with backslashes.

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程