首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redbean MySql插入错误

Redbean MySql插入错误
EN

Stack Overflow用户
提问于 2016-03-23 01:18:51
回答 1查看 1.1K关注 0票数 0

我有以下代码:

代码语言:javascript
复制
Array
(
    [title] => asdas
    [question] => dasdsa
    [gender] => 
    [age] => 
    [description] => 
    [imageUrl] => 
    [plan_id] => 2
    [plan_type] => special
    [plan_price] => 199
    [specialty_id] => 7
    [specialty] => Cardiologist
)

我得到了专业的错误:

代码语言:javascript
复制
Error


RedBeanPHP\RedException Object
(
    [message:protected] => Cannot cast to bean.
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /Applications/XAMPP/xamppfiles/htdocs/site/rb/rb.php
    [line:protected] => 2203
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /Applications/XAMPP/xamppfiles/htdocs/site/rb/rb.php
                    [line] => 2414
                    [function] => __set
                    [class] => RedBeanPHP\OODBBean
                    [type] => ->
                    [args] => Array
                        (
                            [0] => specialty
                            [1] => asdsad
                        )

                )

            [1] => Array
                (
                    [file] => /Applications/XAMPP/xamppfiles/htdocs/site/class/crud.php
                    [line] => 52
                    [function] => offsetSet
                    [class] => RedBeanPHP\OODBBean
                    [type] => ->
                    [args] => Array
                        (
                            [0] => specialty
                            [1] => asdsad
                        )

                )

            [2] => Array
                (
                    [file] => /Applications/XAMPP/xamppfiles/htdocs/site/validate/question/step2.php

                    [line] => 37
                    [function] => insert
                    [class] => crud
                    [type] => ->
                    [args] => Array
                        (
                            [0] => question
                            [1] => Array
                                (
                                    [title] => asdas
                                    [question] => dasdsa
                                    [gender] => 
                                    [age] => 
                                    [description] => 
                                    [imageUrl] => 
                                    [plan_id] => 2
                                    [plan_type] => special
                                    [plan_price] => 199
                                    [specialty_id] => 7
                                    [specialty] => asdsad
                                    [contributor] => dinesh
                                    [created_by] => 1
                                    [ip_address] => ::1
                                    [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0
                                )

                        )

                )

        )

    [previous:Exception:private] => 
)

我花了一个多小时试图解决这个问题,但我仍然不能解决它。

EN

回答 1

Stack Overflow用户

发布于 2016-03-25 01:49:45

您似乎正在尝试保存数组,而不是bean。每次调用R::store()时,都必须传递一个bean。

R::freeze(false);为你创建数据库结构,你只需要切换到流体模式Redbean

对于ex:

代码语言:javascript
复制
R::freeze(false);

$plan = R::dispense('plan');
$plan->description = 'Plan 1';
$bean->planprice = 199.99;

$plantype = R::dispense('plantype');//without underline, ok?!!!
$plantype->description = 'Standard';

$specialty = R::dispense('specialty');
$specialty->description = 'Cardiologist';

$bean = R::dispense('tablename');
$bean->title = 'asdas';
$bean->question = 'dasdsa';
$bean->gender = 1;//1 - Male; 2 - Female;
$bean->age = 39; 
$bean->description = 'bla bla bla';
$bean->imageurl = 'http://urltotheimage/img.jpg';
$bean->plan = $plan;
$bean->plantype = $plantype;
$bean->specialty = $specialty;

R::store($bean);

当您存储$bean时,redbean存储您创建的所有其他bean ($plan, $plantype, $specialty),属性名在列名的末尾带有_id

如果您有一个给定的id,您不需要将$plan保存为bean (如果您已经将注册表存储在数据库中),您只需传递

$bean->plan_id = $givenid;

Redbean是一个令人惊叹的orm工具,但你必须深入它的网站才能使用它;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36161067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档