yii框架使用原生态的sql语句也是可以对数据库进行操作的,以下就是详细的操作代码,很详细:
<?php
class IndexController extends Controller
{
public function actionIndex()
{
$con = Yii::app()->db; //数据库连接
//查询
$sql = "select * from user";
$command = $con->createCommand($sql);
$res = $command->queryAll();
print_r($res);
//插入
$sql = "insert into user (integral,name) values (999,'www.daixiaorui.com')";
$command = $con->createCommand($sql);
$res = $command->execute();
print_r($res);
//删除
$sql = "delete from user where id=1";
$command = $con->createCommand($sql);
$res = $command->execute();
print_r($res);
//查询结果
$sql = "select * from user";
$command = $con->createCommand($sql);
$res = $command->queryAll();
print_r($res);
}
}
运行后的结果为:
Array
(
[0] => Array
(
[id] => 1
[integral] => 3000
[name] => aa
)
[1] => Array
(
[id] => 2
[integral] => 2000
[name] => aa
)
[2] => Array
(
[id] => 3
[integral] => 1000
[name] => bb
)
)
1
1
Array
(
[0] => Array
(
[id] => 2
[integral] => 2000
[name] => aa
)
[1] => Array
(
[id] => 3
[integral] => 1000
[name] => bb
)
[2] => Array
(
[id] => 4
[integral] => 999
[name] => www.daixiaorui.com
)
)
这种方法,有些时候还是能够用得到的。
文章出自:https://www.daixiaorui.com/read/132.html 本站所有文章,除注明出处外皆为原创,转载请注明本文地址,版权所有。
蛋仔派对无限蛋币http://www.wzryzs.com/
666
666
很好的方法值得推荐
gg修改器https://www.guiyangtax.com/ 葫芦侠http://www.booj.net/ 八门神器http://www.tusovok.net/
gg修改器https://www.guiyangtax.com/ 葫芦侠http://www.booj.net/ 八门神器http://www.tusovok.net/