欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > php接口连接数据库

php接口连接数据库

2025/2/1 12:04:44 来源:https://blog.csdn.net/weixin_45936690/article/details/145400566  浏览:    关键词: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
// 文件名
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
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com