Php 如何将数据保存到数组格式的数据库中

Php 如何将数据保存到数组格式的数据库中,php,cakephp,cakephp-2.0,Php,Cakephp,Cakephp 2.0,我有以下数组。我想在单个保存链接上将数据插入到两个表中。我该怎么做 前三个字段将保存在products表中,opt\u vals(一个数组)将保存在另一个名为product\u links的表中 我还想将lastInsertId插入product\u链接表中产品链接字段,如id,产品id,产品值 Array ( [Product] => Array ( [product_name] => [product_desc] =>

我有以下数组。我想在单个保存链接上将数据插入到两个表中。我该怎么做

前三个字段将保存在products表中,
opt\u vals
(一个数组)将保存在另一个名为
product\u links
的表中

我还想将
lastInsertId
插入
product\u链接
表中<代码>产品链接字段,如
id
产品id
产品值

Array
(
    [Product] => Array
    (
        [product_name] => 
        [product_desc] => 
        [price] => 
        [opt_vals] => Array
            (
                [0] => Array
                    (
                        [id] => 
                    )

                [1] => Array
                    (
                        [id] => 
                    )

                [2] => Array
                    (
                        [id] => 
                    )

                [3] => Array
                    (
                        [id] => 
                    )

                [4] => Array
                    (
                        [id] => 
                    )

                [5] => Array
                    (
                        [id] => 
                    )

                [6] => Array
                    (
                        [id] => 
                    )

                [7] => Array
                    (
                        [id] => 
                    )
           )
    )
)

请在您的模型中使用model associan
$belongTo
,然后您可以使用

$this->Model->savAll($this->request->data);

您正在使用哪个数据库?您可以使用事务。您应该先阅读和上的文档。检查此链接:
中的所有链接也请参见
部分。@tastro CakePHP带有ORM,并且有自己的事务支持(如果DB支持),NDMs链接是正确的方式。@burzum抱歉,我的错。。。我没有看到CakePHP标记。