如何在yii框架中使用mysql查询

如何在yii框架中使用mysql查询,yii,Yii,我不熟悉使用yii 1.1.14的yii框架,首先我不了解它。我的目标是从数据库中插入、选择、更新和删除数据。这让我很困惑,请给我举个例子 对于可以使用的查询,对于CRUD可以使用我建议您使用Gii,并使用它生成表的模型 例如,table:user(列:id,name),Model:user 您可以按如下方式插入或更新数据: $user = new User(); // Insert // $user = User::find()->where(['id'=>'1'])->on

我不熟悉使用yii 1.1.14的yii框架,首先我不了解它。我的目标是从数据库中插入、选择、更新和删除数据。这让我很困惑,请给我举个例子

对于可以使用的查询,对于CRUD可以使用

我建议您使用Gii,并使用它生成表的模型

例如,table:user(列:id,name),Model:user

您可以按如下方式插入或更新数据:

$user = new User(); // Insert
// $user = User::find()->where(['id'=>'1'])->one(); // Update
$user->name = "Insert data";
$user->save();
另请参见一些示例

1.在YII2中插入查询

$connection=Yii::$app->db

$connection->createCommand()->insert('tbl_name'[

        'column1' => Yii::$app->request->post('column1'),

        'column2' => Yii::$app->request->post('column2'),   

        ])->execute();
2.更新查询

Yii::$app->db->createCommand()->update('tbl_name'[

        'column1' => Yii::$app->request->post('column1'),

        'column2' => Yii::$app->request->post('column2'),   
    ],
        'where_id ="'.$where.'" ')->execute();