0

我一直在扯头发,向众神献祭——做我能做的功课,但我和这里的其他两个帖子有同样的问题,这两个帖子似乎都没有解决

正确格式化的 MySQL 日期插入语句返回全 0

MYSQL 日期字段总是输出 0000-00-00

当我回显时,我得到了正确格式化的值我使用的是日期而不是日期时间 MySQL 在日期之前正确输入了一个名称,但随后也输入了一个空白的 longblob(图片) - 似乎它只是输入一个字段,或者不知何故我没有正确设置了MySQL还是其他?

我的代码是

catch(PDOException $e)
    {
    echo "Im sorry dave I cant do that";
    echo $e->getMessage();
    }

        //*next bit is to insure that if connection is lost database is not  
   partially updated-I think-
        //* $DBHandle->beginTransaction();

        $firstnameOBS= $_POST['touristfirstname'];
        $todaysdateOBS= $_POST['touristdatetoday'];
        $picturenow= $_POST['picturesubmitted'];

        $JSONfirstname = json_encode($firstnameOBS);
        $JSONtodaysdate = json_encode($todaysdateOBS);
        $JSONpicturenow = json_encode($picturenow);
        echo $JSONtodaysdate ;

        //* Below is the send from PHP page to My Sql Server -
                //*  JSON encode here 

    try {    
        $senditin = $DBHandle->prepare("INSERT INTO 
    `Observations`.`fkarnd`(`firstname`,`datetoday`,`picturesubmitted`) VALUES   
 (:firstname 
    , :datetoday ,:picturesubmitted)", array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));

        //* $senditin->bindValue(':firstname', $JSONfirstname, PDO::PARAM_STR);
        //* $senditin->bindValue(':datetoday', $JSONtodaysdate, PDO::PARAM_STR);
        //* $senditin->bindValue(':picturesubmitted', $JSONpicturenow,
     PDO::PARAM_LOB);

        //* $myinputarray = array('firstname'=> $JSONfirstname, 'datetoday' => 
    $JSONtodaysdate, 'picturesubmitted' => $JSONpicturenow );

        $DBHandle->beginTransaction();
        $senditin->execute(array('firstname'=> $JSONfirstname, 'datetoday' => 
    $JSONtodaysdate, 'picturesubmitted' => $JSONpicturenow ));
        //* commit allows transaction begun to complete
        $DBHandle->commit();

     }  

    catch ( PDOException $e ) {
      echo "I'm sorry, I can't do that Dave......";
      file_put_contents( 'dbErrors.txt', $e->getMessage(), FILE_APPEND );   
        //* rollback function call here? a nasty exception has appeared,      
     }
        echo "<br>"."successful submission";
        $DBHandle = null;

     ?>
4

1 回答 1

2

您的意思是改为调用 json_decode($todaysdateOBS) 吗?看起来这可能是问题的根源,因为 json_encode 将尝试以 json 格式编码您发送给它的任何内容,这不是 sql 中的有效日期字段(http://php.net/manual/en/function .json-encode.php)。

于 2013-03-11T17:41:38.927 回答