doubu2730 2017-04-16 16:48
浏览 50
已采纳

使用JSON / PHP将DATETIME插入到mysql数据库中

I have a database that contains an DATETIME column, I want to insert current date into it using JSON/PHP, but I kept having this error :

Object of class DateTime could not be converted to string in /storage/h3/744/754744/public_html/SendBookingReq.php on line 13 And this is my php file

<?php
require("password.php");
$connect = mysqli_connect("localhost", XXXX, XXXX, XXXX);
$driver_id = $_POST["driver_id"];
$email = $_POST["email"];
$duree = $_POST["duree"];
$distance = $_POST["distance"];
$response = array();
$dt_obj = new DateTime($response['DateTime'], new 
DateTimeZone('America/Chicago')); 
$dt_obj->setTimezone(new DateTimeZone('Europe/Paris')); 
$dt_obj->format('d-m-Y H:i:s');
echo $dt_obj; 
 function AddRequest() {
    global $connect, $driver_id, $email, $duree, $distance, $dt_obj ;
    $statement = mysqli_prepare($connect, "INSERT INTO demande (driver_id, pass_id, duree, distance, send_moment) VALUES (?, (SELECT user_id FROM passager WHERE email = ?), ?, ?, '$dt_obj')");
    mysqli_stmt_bind_param($statement, "isdis", $driver_id, $email, $duree, $distance,$dt_obj);
    mysqli_stmt_execute($statement);
    mysqli_stmt_close($statement);     
}

    $response["success"] = false;  

    AddRequest();
    $response["success"] = true;  

echo json_encode($response);
 ?>

And honestly ,I looked a lot for what letter should I use with datetime ex: "s" for string but I didn't find any.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 SQL 表中 考勤记录的组合查询
      • ¥15 Power pivot无法刷新数据
      • ¥15 刚入职被要求写这种文档,应该如何下手
      • ¥15 最优经济尺寸设计问题
      • ¥15 从多元正态分布中生成3维样本
      • ¥15 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥15 超时跳出方法代码的返回值问题