I am developing a web application in which I am using core php and Parse.com as a database. I referred https://www.parse.com/docs/php_guide#objects-saving .to set a single value to key set() is used and it is mentioned that " Arrays and Associative Arrays require separate methods to set them on a ParseObject. "
<?php
require 'vendor/autoload.php';
use Parse\ParseClient;
ParseClient::initialize('APP ID','REST API ID', 'MASTER ID');
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseUser;
use Parse\ParseInstallation;
class ParseScripts
{
public $object;
public $table;
public function __construct($parse_class=null)
{
$this->object=new ParseObject($parse_class);
$this->table=$parse_class;
}
public function setTable($table)
{
$o=new ParseScripts($table);
return $o;
}
public function insert($data= array())
{
echo "<br>data<pre><br>";
print_r($data);
// $k=array_keys($data);
// print_r($k[0]);
$this->object=new ParseObject($this->table);
// $this->object->setAssociativeArray("$k[0]", $data);
foreach ($data as $key => $value)
{
$this->object->setAssociativeArray("$key", $value);
// echo "key<br>".$key; echo "<br><br>value<br>";print_r($value);
}
try
{
$this->object->save();
echo "object inserted successfully";
} catch (ParseException $exc)
{
echo $exc->getTraceAsString();
}
}
}
$ob=new ParseScripts("qt_topic");
$ob->setTable("qt_topic");
$info= array('topic_name'=>array('Yii 6','Yii 7'));
$ob->insert($info);
?>
In above example if I used setArray() inside foreach it gives error that " Key must be string given array use set()" and if I used set method then it gives error " use setArray or setAssociative array to set the array. It will be better to insert array as a value instead of calling inset() more times for each value. please help me to solve this problem.