douzinei6926 2015-11-16 13:29
浏览 148

插入字符串时缺少前导零


I actually get very mad about PHP and SQLite3 and the way some of my strings behave there.
I try to save opening hours but in strings instead of numeric to prevent problem with leading zeros (and still have it now haha... -.-).
Hours and minutes have their own column but when I insert '0x' the zero is gone and whatever x is, is left in the database. :/
Im sure im just missing some little damn part somewhere...
I already checked the INSERT-statement but found nothing at all.
Example for an insert string:
INSERT INTO opening INSERT INTO opening (start_day, end_day, start_hour, start_minute, end_hour, end_minute) VALUES('Montag', 'Freitag', '00', '00', '01', '00')
But the output is:

11|Montag|Freitag|0|0|1|0

Part of the Code:

class Database_Opening_Hours extends SQLite3{
    function __construct() {
        if(!file_exists("../../data/opening_hours/opening_hours.sqlite")){
            $this->open("../../data/opening_hours/opening_hours.sqlite");
            $this->exec('CREATE TABLE opening (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, start_day STRING, end_day STRING, start_hour STRING, start_minute STRING, end_hour STRING, end_minute STRING)');
        }
        else{
            $this->open("../../data/opening_hours/opening_hours.sqlite");
        }
    }
}
$db = new Database_Opening_Hours();
$insert = "INSERT INTO opening (start_day, end_day, start_hour, start_minute, end_hour, end_minute) VALUES('".htmlspecialchars($_GET["start_day"])."','".htmlspecialchars($_GET["end_day"])."','".$start_hour."','".$start_minute."','".$end_hour."','".$end_minute."')";
if($db->exec($insert)){
    $db->close();
    unset($db);
    echo "Insert erfolgreich";
}else{
    $db->close();
    unset($db);
    echo "Nicht wirklich...";
}
  • 写回答

4条回答 默认 最新

  • douyu1656 2015-11-16 13:32
    关注

    Fairly sure that the type of your columns is set to an integer (or any other number type) instead of TEXT.

    Make sure to double check the column data type and actually dump the table for us to check if it's really set to TEXT.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用