CI4操作数据库

function ddd()
    {
        try {
            $db      = db_connect();        //创建数据库连接

            $rs   = $db->table('news t1')->get()->getResult();     //查询(查询结束后,不会重置数据库连接,后面的内容依然会继续执行)

            $data['title'] = 'al123123jfl55ajsdf';
            $data['content'] = 8723981723891273;

            $db->table('news')->insert($data);  //插入

            $rs = $db->insertID();      //获取返回id

            $rs = $db->join('news t2', 't1.id=t2.id')->get()->getResult();

            $rs = $db->table('news')->upsert($data);    //插入更新

        } catch (\Throwable $th) {
            p($th);
        }
    }

 

posted @ 2024-08-27 15:35  哆啦阿梦  阅读(26)  评论(0)    收藏  举报