thinkphp5 原生sql查询及取返回值

刚接触php,以前大量数据库都是直接写sql的,方便,好管理,

用thinkphp后,发现没有sql,对mvc模式还没深入了解,但这边要在上面写一些接口,有涉及数据库查询,修改等,只能用原生sql去操作,写sql真的很爽。

我用ci架构时,数据库是sqlserver,里面用了存储过程,哈哈,以前写CS的,存储过程必须要666

thinkpad写api接口很方便。

原生sql使用方法如下:

复制代码
//连接另一个数据库  ,我有多个库   
$db=Db::connect(config('db'));
$sql = "select signstr from userinfo where  usercode = :usercode";
//注意传参
$result = $db->query($sql,['usercode'  => $user]);
//如果不为空,取数据库返回值
if($result)
{
  //取数组字段
  $signstr = array_column($result, 'signstr');
  //取值返回
  $this->success(10000,"successed:".$signstr[0]);
}
相关推荐
翔云12345611 分钟前
在MySQL中,使用物理备份工具 xtrabackup备份扩容从库,从库上的gtid_executed和gtid_purged变化过程
数据库·mysql
liulilittle1 小时前
Linux shell 搜索指定后缀名文件,并复制到指定目录。
linux·服务器·数据库
必胜刻1 小时前
Redis哨兵模式(Linux)
linux·数据库·redis
dualven_in_csdn1 小时前
【数据库损坏】关于一次现场数据库损坏
数据库·mysql
锦衣夜行?2 小时前
oracle 未知长度从左到右截取某个字符串
数据库·oracle
han_hanker2 小时前
@JsonIgnore,@JsonProperty, @JsonInclude,@JsonFormat
数据库·oracle
hanyi_qwe2 小时前
MySQL事务基础
数据库·mysql
l1t2 小时前
三种用SQL解决Advent of Code 2022第8题 树顶木屋 的比较和分析
数据库·sql·oracle·duckdb·advent of code
如果未来,2 小时前
Oracle的Redo log和Undo log的区别
数据库·oracle
koping_wu2 小时前
【方案设计】Mysql相关场景
数据库·mysql