【问题标题】:Error display while i fire insert query in postgresql , but it can not insert the data in my postgresql. why?我在 postgresql 中触发插入查询时显示错误,但它无法在我的 postgresql 中插入数据。为什么?
【发布时间】:2016-07-19 06:14:14
【问题描述】:
INSERT INTO soma_user_unit_booking ( 
    uid, book_status, book_datetime, dom_id, from_date, to_date, from_time, to_time, event
) VALUES ( 
   '4','1','2016-07-18 18:01:04','27','2016-07-20','2016-07-20','11:00','11:30','Booking'
)
  • 我尝试在服务器中执行插入查询。并在服务器中安装了 postgresql 数据库。
  • 当我执行这个插入查询时,数据没有插入到数据库中。和一个错误显示(最后附上图片)。并且数据不能在数据库中插入记录。
  • 另一个,当我在 pgadmin 中调用静态查询时,如果我检查(分页结果)选项,则查询不会运行,当取消选中它时,它将在 Postgre 数据库中成功运行。

你能告诉我如何解决这些问题吗?

for reference these image, in which i check and unchecked the paginate option in server database.

these error display while executing

【问题讨论】:

  • 当您在psql 中运行此语句时,您会看到什么输出?..
  • -这些错误在执行时显示。 sql 语法错误:错误:“INTO”第 1 行或附近的语法错误:SELECT COUNT() as total FROM (INSERT INTO soma_user_unit_bo..) SELECT COUNT() AS total (INSERT INTO soma_user_unit_booking (uid) , book_status, book_datetime, dom_id, from_date, to_date, from_time , to_time, event ) 值 ('4', '1', '2016-07-18 18:01:04', '27', '2016-07-20 ', '2016-07-20', '11:00' , '11:30', 'Booking' )) AS sub
  • 这不是您在问题中向我们展示的陈述 - 请更新问题以保留您尝试运行的确切陈述和获得的准确输出
  • 好的。编辑!谢谢。
  • 如果我取消选中服务器中的分页结果选项,那么它将运行我的插入查询。但是插入查询和分页结果之间的关系是什么。默认情况下它选项被选中

标签: php database postgresql pgadmin


【解决方案1】:

尝试使用 PDO。这是一个简单的例子:

try { $db = new PDO(DB_DRIVER . ":dbname=" . DB_DATABASE . ";host=" . DB_SERVER, DB_USER, DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("INSERT INTO countries(name, capital, language) VALUES (:country, :capital, :language)");

$stmt->bindParam(':country', $country);
$stmt->bindParam(':capital', $capital);
$stmt->bindParam(':language', $language);

if($stmt->execute()) {
  echo '1 row has been inserted';  
}
$db = null;} catch(PDOException $e) {

trigger_error('Error occured while trying to insert into the DB:' . $e->getMessage(), E_USER_ERROR); }

【讨论】:

  • 当我执行你的代码时,数据库连接成功,但是它显示空白页并且没有任何错误显示。请帮帮我。
  • 你能把更新后的查询语句贴在这里吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2015-05-23
相关资源
最近更新 更多