Insert Items into Parse via PHP SDK

Example code for inserting a new object into Parse.com’s datastore.

<?php
$resort_qry = "SELECT
res_id
,resort as name
,res_about as description
,res_state as state
,x(res_map_point) AS lat
,y(res_map_point) AS lng
,created_date
,'dsadafe,dseaDS12d' as concat_str
FROM
resorts
WHERE
res_id in (1,2,3)";
$results = $enviro->conn->db->Execute($resort_qry);
while($row = $results->FetchRow()) {
try{
$parse = ParseObject::create("resort");
//Load a string
$parse->set("resort_name", $row['name']);
//Load a number
$parse->set("resort_id", intval($row['res_id']));
//Load a geolocation
$point = new ParseGeoPoint(setParseFloatFormat($row['lat']), setParseFloatFormat($row['lng']));
$parse->set("location", $point);
//Load a Date
$exp_date = new DateTime($row['created_date']);
$parse->set("expireDate",$exp_date);
//Load a boolean
$parse->set("flag", true);
//Load an array
$list = explode(",",$row['concat_str']);
$parse->setArray("arrayList", $list);
//Load a pointer
$parentObj = new ParseObject("testofObject", "tcrxhw9WIA");
$parse->set("testObjectId",$parentObj);
$parse->save();
}catch(ParseException $ex){
echo $ex->getCode();
echo $ex->getMessage();
}
$new_resort_parse_id = $parse->getObjectId();
$upd_res_qry = "UPDATE resorts SET resortObjectId = ? WHERE res_id = ?";
$upd_result = $enviro->conn->db->Execute($upd_res_qry, array($new_resort_parse_id, $row['res_id']));
}?>
view raw ParseInsertExample hosted with ❤ by GitHub
<?php
$resort_qry = "SELECT
res_id
,resort as name
,res_about as description
,res_state as state
,x(res_map_point) AS lat
,y(res_map_point) AS lng
,created_date
,'dsadafe,dseaDS12d' as concat_str
FROM
resorts
WHERE
res_id in (1,2,3)";
$results = $enviro->conn->db->Execute($resort_qry);
while($row = $results->FetchRow()) {
try{
$parse = ParseObject::create("resort");
//Load a string
$parse->set("resort_name", $row['name']);
//Load a number
$parse->set("resort_id", intval($row['res_id']));
//Load a geolocation
$point = new ParseGeoPoint(setParseFloatFormat($row['lat']), setParseFloatFormat($row['lng']));
$parse->set("location", $point);
//Load a Date
$exp_date = new DateTime($row['created_date']);
$parse->set("expireDate",$exp_date);
//Load a boolean
$parse->set("flag", true);
//Load an array
$list = explode(",",$row['concat_str']);
$parse->setArray("arrayList", $list);
//Load a pointer
$parentObj = new ParseObject("testofObject", "tcrxhw9WIA");
$parse->set("testObjectId",$parentObj);
$parse->save();
}catch(ParseException $ex){
echo $ex->getCode();
echo $ex->getMessage();
}
$new_resort_parse_id = $parse->getObjectId();
$upd_res_qry = "UPDATE resorts SET resortObjectId = ? WHERE res_id = ?";
$upd_result = $enviro->conn->db->Execute($upd_res_qry, array($new_resort_parse_id, $row['res_id']));
}?>
view raw ParseInsertExample2 hosted with ❤ by GitHub