繁体   English   中英

PHP:处理记录的对象,而不仅仅是一条记录

[英]PHP: Processing an object of records, not just one record

当前,此服务调用仅插入一个(1)记录。 但是我需要能够向该方法发送一个真实的对象,该对象带有在此调用期间要插入的多个记录:

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;
}

我将如何更改它以便可以传递关联数组或类似的东西?

我试过将语句包装在foreach语句中,但似乎不起作用。 :/

注意 :如果这很重要,我将从Flash发送数据。

使用error_log(print_r($ asset,true))-这会将传递的对象的结构转储到PHP日志中。 然后,您可以使用foreach或for / next或其他任何循环方式。 也许您正在尝试遍历不存在的结构,或者在传入时格式不同的结构?

将复杂的对象从Flash / Flex传递到PHP完全可以。 没有理由你不能在这里做你想做的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM