时间:2021-07-01 10:21:17 帮助过:26人阅读
(二)使用database.php + 控制器的方式工作
在database.php里配置:
- <span style="color: #0000ff">return</span><span style="color: #000000"> [
- </span><span style="color: #008000">//</span><span style="color: #008000"> 数据库类型</span>
- ‘type‘ => ‘Sqlsrv‘, <span style="color: #008000">//</span><span style="color: #008000">必须输入<br>
- // 用户名</span>
- ‘username‘ => ‘sa‘,
- <span style="color: #008000">//</span><span style="color: #008000"> 密码</span>
- ‘password‘ => ‘yoooko‘,
- <span style="color: #008000">//</span><span style="color: #008000"> 连接dsn,驱动、服务器地址和端口、数据库名称</span>
- ‘dsn‘ => ‘odbc:Driver={SQL Server};Server=127.0.0.1\sql2000,1434;Database=master‘,<span style="color: #000000">
- ];</span>
在Index.php控制器里:
- <?<span style="color: #000000">php
- namespace app\index\controller;
- </span><span style="color: #0000ff">use</span><span style="color: #000000"> think\Db;
- </span><span style="color: #0000ff">class</span><span style="color: #000000"> Index
- {
- </span><span style="color: #0000ff">public</span> <span style="color: #0000ff">function</span><span style="color: #000000"> index()
- {
- </span><span style="color: #008080">header</span>(‘Content-type:text/html; charset=utf-8‘<span style="color: #000000">);
- </span><span style="color: #008000">//</span><span style="color: #008000">$user = Db::table(‘cs‘)->select(); //不行,有row_number()错误</span>
- <span style="color: #800080">$user</span> = Db::query("select * from cs"); <span style="color: #008000">//</span><span style="color: #008000">必须使用原生sql方式,正确</span>
- <span style="color: #0000ff">echo</span> ‘<pre>‘<span style="color: #000000">;
- </span><span style="color: #008080">print_r</span>(<span style="color: #800080">$user</span><span style="color: #000000">);
- </span><span style="color: #0000ff">echo</span> ‘</pre>‘<span style="color: #000000">;
- }
- }</span>
thinkphp5访问sql2000数据库
标签:两种 use nbsp 下载 print could not html mss ace