所以我試圖運行一個查詢插入一些值到我的postgres數據庫,但我遇到了一些問題。對於初學者來說,當我運行此:使用PHP的PDO插入HSTORE數組
INSERT INTO DataBin (createdUserId, objectId, objData) VALUES ('52dcd7c7-d300-4394-9f76-e756237951ce', 'd44279a8-3613-4a3c-9a2a-d74770f58a6e', hstore(ARRAY['f9868417-6e91-4c1b-ab67-bcc9290de085', NOW()::TEXT, '7d1d3e16-8b39-4e80-a068-8ed533377dca', 52.03::TEXT, '2123d903-0030-4cb2-abad-d3a48328be97', 20::TEXT])) ;
查詢似乎完全正常工作,但努力做到以下幾點的時候,它給了我一個錯誤:
Notice: Array to string conversion
$db = new PDO("pgsql:host=localhost;port=5432;dbname=test;user=postgres;password=postgres");
//-- Long ass insert for a databin
$stmt = $db->prepare('INSERT INTO DataBin (createdUserId, objectId, objData) VALUES (?, ?, ?)');
$date = new DateTime();
$hstore = array($time["id"], $date->getTimestamp(), $weight["id"],'52.03', $height["id"],'20');
$stmt->bindParam(1, $user["id"]);
$stmt->bindParam(2, $object["id"]);
$stmt->bindParam(3, $hstore);
$stmt->execute();
我假設我沒有正確解析數組,以使postgres HSTORE正常工作。任何幫助,將不勝感激。