php - 我如何在 controller.php 中将 redis 更改为 mysql

标签 php mysql laravel redis mariadb

如何将其更改为不使用 redis。在 .env 中,我没有将 redis 作为 DB_CONNECTION。 idk 我怎么能删除这个 redis,因为没有 ingerence 我无法启动我的网站...非常感谢帮助和任何答案。

这是我的 controller.php,其中 31-33 有错误

<?php

namespace App\Http\Controllers;

use Auth;
use LRedis;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController
{
    use DispatchesJobs, ValidatesRequests;

    public $user;
    public $redis;
    public $title;

    public function __construct()
    {
        $this->setTitle('Title not stated');
        if(Auth::check())
        {
            $this->user = Auth::user();
            view()->share('u', $this->user);
        }
        $this->redis = LRedis::connection();
        view()->share('steam_status', $this->getSteamStatus());
    }

    public function  __destruct()
    {
        $this->redis->disconnect();
    }

    public function setTitle($title)
    {
        $this->title = $title;
        view()->share('title', $this->title);
    }

    public function getSteamStatus()
    {
        $inventoryStatus = $this->redis->get('steam.inventory.status');
        $communityStatus = $this->redis->get('steam.community.status');

        if($inventoryStatus == 'normal' && $communityStatus == 'normal') return 'good';
        if($inventoryStatus == 'normal' && $communityStatus == 'delayed') return 'normal';
        if($inventoryStatus == 'critical' || $communityStatus == 'critical') return 'bad';
        return 'good';
    }

}

这是我的.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=l2ggh1imVxJ7Oj6BotPUWinAIDgJfBYw
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=csgo
DB_USERNAME=root
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=4563

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

pplssss 帮助我!

最佳答案

你可以像这样访问你的数据库表
首先,您需要在文件顶部添加此代码

use Illuminate\Support\Facades\DB;

然后

$steamDetail= DB::table('steam')->get();//This will return all the data from steam table
$steamStatusArray=DB::table('steam')->pluck('status');//This will return only the status column from steam table

Reference- Laravel Query Builder
注意:你必须删除所有与LRedis

相关的代码 如果你不知道从哪里开始试试这个 tutorial 。它可能会给您灵感。

关于php - 我如何在 controller.php 中将 redis 更改为 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133149/

相关文章:

php - Bootbox.js 提交表单前确认选择

php - Laravel Mix 多个入口点生成一个 manifest.js

php - 使用不同的查询选择和排序数据

mysql - mySQL 动态列标题出错

laravel - 无法在Heroku上部署Laravel应用程序的Docker镜像

mysql - 如何检索所有未回答的问题)?

php - Json 在插入时解码 undefined index

php - 用于发布书籍/文档的 PHP 脚本

PHP 登录系统在我点击登录后不显示任何内容

PHP基本比较负