西安网站建设查派,网站的优化方案,手机网站生成代码,照片变年轻在线制作网站环境信息
操作系统win11php 8.4.1webman-framework ^1.6.8MySQL 8.4.3topthink/think-orm ^3.0
说明
PHP8.3以下版本 直接使用webman提供的webman/think-orm更方便。 PHP 环境换为 8.4 使用webman/think-orm 报了个错#xff1b;所以换topthink/think-orm#xff0c;根据文…环境信息
操作系统win11php 8.4.1webman-framework ^1.6.8MySQL 8.4.3topthink/think-orm ^3.0
说明
PHP8.3以下版本 直接使用webman提供的webman/think-orm更方便。 PHP 环境换为 8.4 使用webman/think-orm 报了个错所以换topthink/think-orm根据文档其支持PHP8.0但实际情况还是报相同的错错误的暴力修改 在最后。 PHP8.4 较新 可能更多框架未及时更新 以下方法勿用于生产。
webman直接使用 topthink/think-orm
webman的相关文档业务初始化 业务初始化文档地址 先熟读此文档再做后续设置。topthink/think-orm 的gitee仓库 及文档连接。根据topthink/think-orm的文档说明安装后只需要设置数据库配置信息即可。
use think\facade\Db;
Db::setConfig([
//配置数据看官网
]);所以只要在webman 启动时做上述设置即可。 以下的配置Linux的设置也是一致 4.1 建找个命名空间目录建个新的PHP文件放置如下代码
?php
//命名空间根据自己的实际情况来
namespace app\init;use Webman\Bootstrap;
use Workerman\Worker;use think\facade\Db;
// use support\Log;//注意类名需要和文件名一致
class ThinkOrmInit implements Bootstrap
{public static function start(?Worker $worker){$databaseConfig config(think_orm);//在config目录下建的一个think_orm.php配置文件,文件名随便配置复制官网的// Log::info(databaseConfig:.json_encode($databaseConfig));if ($databaseConfig) {Db::setConfig($databaseConfig);// Db::connect();//AI生成是有此但官方文档不需要所以没要}}}
4.2 修改config目录下的 bootstrap.php 配置
?php
return [support\bootstrap\Session::class,support\bootstrap\LaravelDb::class,app\init\ThinkOrmInit::class,//是的就是增加这个
];PHP的 php.ini 文件开启 extensionpdo_mysql。 4.3 定义数据模型、数据的写入。注 只测了模型数据写入Db::name(user)-save($data);这样的数据写入没测试试。
注意
只在前面提到的环境下测试其他环境下需要进一步验证。
暴力修改 topthink/think-orm 3.0 在PHP8.4的警告
下面描述的异常可能是我配置信息没设置对导致$name是null触发的熟悉 think-orm的朋友指导一下谢谢。 异常内容如下 ErrorException: think\DbManager::connect(): Implicitly marking parameter $name as nullable is deprecated, the explicit nullable type must be used instead in E:\x\项目\vendor\topthink\think-orm\src\DbManager.php:221 我的修改找到文件、行然后直接修改 221行
//原
public function connect(string $name null, bool $force false)//改后 string $name 前加个 ? 号
public function connect(?string $name null, bool $force false)234行也有同样的错
//原
protected function instance(string $name null, bool $force false): ConnectionInterface
//改后
protected function instance(?string $name null, bool $force false): ConnectionInterface
文章转载自: http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.npbkx.cn.gov.cn.npbkx.cn http://www.morning.drjll.cn.gov.cn.drjll.cn http://www.morning.sfhjx.cn.gov.cn.sfhjx.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.hxwrs.cn.gov.cn.hxwrs.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.nrll.cn.gov.cn.nrll.cn http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.khlxd.cn.gov.cn.khlxd.cn http://www.morning.ynryz.cn.gov.cn.ynryz.cn http://www.morning.lpyjq.cn.gov.cn.lpyjq.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.nnpfz.cn.gov.cn.nnpfz.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn http://www.morning.fywqr.cn.gov.cn.fywqr.cn http://www.morning.slmbg.cn.gov.cn.slmbg.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.ybgt.cn.gov.cn.ybgt.cn http://www.morning.zsrjn.cn.gov.cn.zsrjn.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn http://www.morning.lpmlx.cn.gov.cn.lpmlx.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.jrgxx.cn.gov.cn.jrgxx.cn http://www.morning.hlppp.cn.gov.cn.hlppp.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.blxlf.cn.gov.cn.blxlf.cn http://www.morning.hhxkl.cn.gov.cn.hhxkl.cn http://www.morning.qmrsf.cn.gov.cn.qmrsf.cn http://www.morning.rxnr.cn.gov.cn.rxnr.cn http://www.morning.pxlql.cn.gov.cn.pxlql.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.ngqty.cn.gov.cn.ngqty.cn http://www.morning.xqkjp.cn.gov.cn.xqkjp.cn http://www.morning.ltqzq.cn.gov.cn.ltqzq.cn http://www.morning.kbqbx.cn.gov.cn.kbqbx.cn http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn http://www.morning.drzkk.cn.gov.cn.drzkk.cn http://www.morning.cnyqj.cn.gov.cn.cnyqj.cn http://www.morning.brjq.cn.gov.cn.brjq.cn http://www.morning.fnssm.cn.gov.cn.fnssm.cn http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn http://www.morning.jgzmr.cn.gov.cn.jgzmr.cn http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn http://www.morning.rkxk.cn.gov.cn.rkxk.cn http://www.morning.nmngg.cn.gov.cn.nmngg.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.plqkz.cn.gov.cn.plqkz.cn http://www.morning.ltbwq.cn.gov.cn.ltbwq.cn http://www.morning.ssqwr.cn.gov.cn.ssqwr.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.slmbg.cn.gov.cn.slmbg.cn http://www.morning.cflxx.cn.gov.cn.cflxx.cn http://www.morning.rzmkl.cn.gov.cn.rzmkl.cn http://www.morning.clccg.cn.gov.cn.clccg.cn http://www.morning.fyglg.cn.gov.cn.fyglg.cn http://www.morning.brld.cn.gov.cn.brld.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.mxhys.cn.gov.cn.mxhys.cn http://www.morning.ymwcs.cn.gov.cn.ymwcs.cn http://www.morning.ryztl.cn.gov.cn.ryztl.cn http://www.morning.sgbsr.cn.gov.cn.sgbsr.cn http://www.morning.hjbrd.cn.gov.cn.hjbrd.cn http://www.morning.jhrqn.cn.gov.cn.jhrqn.cn http://www.morning.flzqq.cn.gov.cn.flzqq.cn http://www.morning.pxwjp.cn.gov.cn.pxwjp.cn http://www.morning.pznqt.cn.gov.cn.pznqt.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn