Home > Backend Development > PHP Tutorial > thinkPHP模型初始化实例分析_PHP

thinkPHP模型初始化实例分析_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-29 11:47:54
Original
1155 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();
*/
Copy after login

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

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

Copy after login

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

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

Copy after login

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

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

Copy after login

希望本文所述对大家基于thinkPHP框架的PHP程序设计有所帮助。

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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template