php接口连接数据库

框架:https://www.thinkphp.cn/doc

创建网站

域名自己写

创建文件夹,"test"拉取框架,地址栏输入

composer create-project topthink/think=5.1.* tp5

会自动创建一个tp5文件夹

根目录选择刚刚创建拉框架的文件夹

以test为示例

"D:\test\tp5"

配置文件:

D:\test\tp5\config\app.php

默认地址:

D:\test\tp5\application\index\controller\ index.php

php 复制代码
<?php
// 文件名
namespace app\index\controller;
//类名
class Test
{					// 函数名 (参数)
    public function hello($name)
    {			//	.拼接
        return $name . 'acb';
    }

    public function hello1()
    {		// json格式
    		// db引用数据库
    		// couple表明
    		// select() 查找全部
      return json(db('couple')->select()) ;
        return 'acb';
    }
}

数据库配置:

D:\test\tp5\config

在页面访问:

http://localhost:9001/public/index.php/index/test/hello1

相关推荐
JaguarJack5 分钟前
为什么 PHP 闭包要加 static?
后端·php·服务端
ServBay1 天前
垃圾堆里编码?真的不要怪 PHP 不行
后端·php
用户962377954481 天前
CTF 伪协议
php
BingoGo3 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php
JaguarJack3 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php·服务端
BingoGo4 天前
OpenSwoole 26.2.0 发布:支持 PHP 8.5、io_uring 后端及协程调试改进
后端·php
JaguarJack4 天前
OpenSwoole 26.2.0 发布:支持 PHP 8.5、io_uring 后端及协程调试改进
后端·php·服务端
JaguarJack5 天前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
后端·php·服务端
BingoGo5 天前
推荐 PHP 属性(Attributes) 简洁读取 API 扩展包
php
JaguarJack6 天前
告别 Laravel 缓慢的 Blade!Livewire Blaze 来了,为你的 Laravel 性能提速
后端·php·laravel