2016-03-22 14 views
0

I次のコードを持っている:Redbean MySQLの挿入エラー

Array 
(
    [title] => asdas 
    [question] => dasdsa 
    [gender] => 
    [age] => 
    [description] => 
    [imageUrl] => 
    [plan_id] => 2 
    [plan_type] => special 
    [plan_price] => 199 
    [specialty_id] => 7 
    [specialty] => Cardiologist 
) 

私が専門のため、エラーを取得しています:私はこの問題を解決しようとすると1時間以上を費やし

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] => 
) 

を、と私は思いまだそれを修正することができません。

+0

コードがPHPであると仮定すると、文字列をかっこで囲む必要がありますか? 'rb.php'の' 2203'行も表示しますか? – PinkTurtle

+0

は、これは私のparamsある アレイ ( [タイトル] => asdas [質問] => dasdsa [性別] => [年齢] => [説明] => [IMAGEURL] => [ plan_id] => 2 [plan_type] =>特別 [plan_price] => 199 [specialty_id] => 7 [専門] =>心臓内科医 ) –

+0

は、あなたがその正常に動作し専門のparamを削除した場合。 –

答えて

0

Beanの代わりに配列を保存しようとしているようです。常にR::store()に電話すると、Beanを渡す必要があります。あなたが作成した

あなたは$豆を保存
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); 

、redbean店舗ごとに他の豆($plan, $plantype, $specialty

はRedbeanはあなただけEX用流体モードR::freeze(false);

に切り替える必要があり、あなたのためのデータベース構造を作成し、 )列名の末尾に_idのattr名を付けてください。

あなたが指定したidを持っている場合、あなたは(あなたが既にデータベースに保存されたレジストリを持っている場合)あなただけの

$bean->plan_id = $givenid;

Redbeanは素晴らしいORMであるに合格する必要がBeanとして$planを保存する必要がいけませんツールを使用することができますが、内部で作業するにはサイトを深くする必要があります。

+0

私はspecialty_textを使いたいですか? –

+0

同じ概念は、他のテーブルを使用して、その特殊フィールドに正しく挿入されています。 –

+0

テーブル名に '_'を使用することはできませんが、rbの中でメソッド' runQuery'を検索するのに役立つように、カラム名には使用できません。データベース上でRedbeanが実行されていることを確認できるよりも、 '$ sql'と' $ bindings'変数をPHPでログに記録してください –