Home > php教程 > php手册 > thinkPHP模型初始化实例分析

thinkPHP模型初始化实例分析

WBOY
Release: 2016-06-06 19:36:26
Original
1036 people have browsed it

这篇文章主要介绍了thinkPHP模型初始化的方法,结合实例形式分析了thinkPHP模型初始化及数据库操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

/* $dsn = 'mysql://bookman:book123@localhost:3306/Weapons'; $guns_tab = M('guns','',$dsn); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1); */ /* $guns_tab = M('guns'); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1); */ $guns_tab = new GunsModel(); $gun1 = $guns_tab ->select() -> page('1,1'); echo $guns_tab -> getLastSql(); dump($gun1); $guns_tab -> showInfo(); /* $guns_tab = new DetectModel('guns'); $gun1 = $guns_tab -> select(); echo $guns_tab -> getLastSql(); dump($gun1); $guns_tab -> showInfo(); */

1.脱离配置文件产生的连接方式

$dsn = 'mysql://bookman:book123@localhost:3306/Weapons'; $guns_tab = M('guns','',$dsn); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1);

2.依照配置文件连接数据库,表名一定要区分清楚

$guns_tab = M('guns'); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1);

3.我有一个自定义的模型,里面实现了自己的业务方法,我还有一个guns的表于是可以这样初始化模型。既可以获取guns表中的数据,还可以使用我自定义模型中的业务方法。

$guns_tab = new DetectModel('guns'); $gun1 = $guns_tab -> select(); echo $guns_tab -> getLastSql(); dump($gun1); $guns_tab -> showInfo();

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template