Currently, this service call only inserts a single (1) record. But I need to be able to send this method a true object with multiple records to be inserted during this call:
public function savePresentation($assets) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (presentationid, assetid, positionid) VALUES (?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iii', $assets->presentationid, $assets->assetid, $assets->positionid);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
How would I change this so that I can pass an associative array, or something similar?
I've tried wrapping the statement in a foreach
statement, but it doesn't seem to work. :/
NOTE: I'm sending the data from Flash, if that matters at all.
Use error_log(print_r( $asset, true )) - this will dump the structure of your passed object out to the PHP log. Then you can use foreach or for / next or whatever to loop through it. Maybe you're trying to loop on a structure that doesn't exist or is formatted differently when it gets passed in?
Its totally fine to pass complex objects from Flash/Flex into PHP. No reason you can't do what you're trying here.