您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-數據庫-快速開始
发布时间:2022-01-30 12:45:26编辑:雪饮阅读()
webman数据库默认采用的是 illuminate/database,也就是laravel的数据库,用法与laravel相同。
安裝:
[root@localhost webman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini /usr/local/bin/composer require illuminate/database ^8.0
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
./composer.json has been updated
Running composer update illuminate/database
Loading composer repositories with package information
Updating dependencies
Lock file operations: 7 installs, 0 updates, 0 removals
- Locking illuminate/database (v8.81.0)
- Locking symfony/console (v5.4.3)
- Locking symfony/polyfill-intl-grapheme (v1.24.0)
- Locking symfony/polyfill-intl-normalizer (v1.24.0)
- Locking symfony/polyfill-php73 (v1.24.0)
- Locking symfony/service-contracts (v2.5.0)
- Locking symfony/string (v5.4.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
- Downloading symfony/polyfill-intl-normalizer (v1.24.0)
- Downloading symfony/polyfill-intl-grapheme (v1.24.0)
- Downloading symfony/string (v5.4.3)
Failed downloading symfony/string, trying the next URL (404: The "https://mirrors.aliyun.com/composer/dists/symfony/string/92043b7d8383e48104e411bc9434b260dbeb5a10.zip" file could not be downloaded (HTTP/1.1 404 Not Found))
- Downloading symfony/string (v5.4.3)
- Downloading symfony/service-contracts (v2.5.0)
- Downloading symfony/polyfill-php73 (v1.24.0)
- Downloading symfony/console (v5.4.3)
Failed downloading symfony/console, trying the next URL (404: The "https://mirrors.aliyun.com/composer/dists/symfony/console/a2a86ec353d825c75856c6fd14fac416a7bdb6b8.zip" file could not be downloaded (HTTP/1.1 404 Not Found))
- Downloading symfony/console (v5.4.3)
- Downloading illuminate/database (v8.81.0)
Failed downloading illuminate/database, trying the next URL (404: The "https://mirrors.aliyun.com/composer/dists/illuminate/database/2dab88ccaf750e3e79d51ddd0b2c94f5f11c8d77.zip" file could not be downloaded (HTTP/1.1 404 Not Found))
- Downloading illuminate/database (v8.81.0)
- Installing symfony/polyfill-intl-normalizer (v1.24.0): Extracting archive
- Installing symfony/polyfill-intl-grapheme (v1.24.0): Extracting archive
- Installing symfony/string (v5.4.3): Extracting archive
- Installing symfony/service-contracts (v2.5.0): Extracting archive
- Installing symfony/polyfill-php73 (v1.24.0): Extracting archive
- Installing symfony/console (v5.4.3): Extracting archive
- Installing illuminate/database (v8.81.0): Extracting archive
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
10 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
26 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
數據庫配置:
config/database.php:
<?php
return [
// 默认数据库
'default' => 'mysql',
// 各种数据库配置
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => 'workerman',
'username' => 'xy',
'password' => 'xy',
'unix_socket' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'phome_',
'strict' => true,
'engine' => null,
],
],
];
app/controller/Index.php控制器中數據庫的應用:
<?php
namespace app\controller;
use support\Request;
use support\Db;
class Index
{
public function index(Request $request)
{
$id = 86;
$name = Db::table('ecms_news')->where('id', $id)->value('username');
return response("hello $name");
}
public function view(Request $request)
{
return view('index/view', ['name' => 'webman']);
}
public function json(Request $request)
{
return json(['code' => 0, 'msg' => 'ok']);
}
}
實例啓動后客戶端訪問結果:
[root@localhost webman]# elinks http://127.0.0.1:8787/Index/index --dump
hello 雪饮
关键字词:webman,數據庫,快速開始