亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

第 15 集的問題 laracasts.com PHP 從業者

第 15 集的問題 laracasts.com PHP 從業者

PHP
手掌心 2023-12-15 15:09:09
這一集是關于隱藏密碼的。我收到刷新本地主機的錯誤 - “無法找到驅動程序”如視頻所示制作 config.php 后。連接.php<?phpclass Connection{    public static function make($config)    {        try {/*            return new PDO('mysql:host=localhost:3306;dbname=schema_test', 'name', 'password');*/            return new PDO(                $config['connection'].';dbname='.$config['name'],                $config['username'],                $config['password'],                $config['options']            );        } catch (PDOException $e) {            die($e->getMessage());        }    }}它適用于注釋掉的版本,但在制作 config.php 并從那里獲取信息后,我收到了錯誤。配置文件<?phpreturn [    'database' => [        'name' => 'schema_test',        'username' => 'name',        'password' => 'password',        'connection' => 'localhost:3306',        'options' => [],    ]];引導程序.php<?phprequire 'database/Connection.php';require 'database/QueryBuilder.php';$config = require 'config.php';return new QueryBuilder(    Connection::make($config['database']));另外,我在控制臺中沒有得到有關錯誤的其他信息。我已經嘗試過對其他人有效的解決方案,例如: sudo apt-get install php-mysql我嘗試重新安裝一些與 php 相關的東西,但這也沒有改變任何東西。<?phprequire 'database/Connection.php';require 'database/QueryBuilder.php';$config = require 'config.php';print_r($config);return new QueryBuilder(    Connection::make($config['database']));輸出:Array ( [數據庫] => Array ( [名稱] => schema_test [用戶名] => 用戶 [密碼] => 密碼 [連接] => localhost:3306 [選項] => Array ( ) ) ) SQLSTATE[HY000] [1045] 用戶“user”@“localhost”的訪問被拒絕(使用密碼:YES)
查看完整描述

2 回答

?
犯罪嫌疑人X

TA貢獻2080條經驗 獲得超4個贊

您沒有聲明驅動程序,因此您得到'could not find driver'。此外,您還缺少命名 host= 參數。


要糾正此錯誤,請像這樣更改 PDO 實例化:


return new PDO(

    'mysql:host='.$config['connection'].';dbname='.$config['name'],

    $config['username'],

    $config['password'],

    $config['options']

 );

您的$config數組沒有問題,并且也被正確包含。</span>


查看完整回答
反對 回復 2023-12-15
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

在 config.php 中,直接設置數組:


<?php


$config = [

    'database' => [

        'name' => 'schema_test',

        'username' => 'name',

        'password' => 'password',

        'connection' => 'mysql:host=localhost:3306',

        'options' => [],

    ]

];

在您的 bootstrap.php 中,請要求您的 config.php 文件如下:


require 'config.php';

并且不要忘記使用 $config['database']['name']...


查看完整回答
反對 回復 2023-12-15
  • 2 回答
  • 0 關注
  • 183 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號