在XAMPP中运行代码时出错 [英] Error while running the code in XAMPP
本文介绍了在XAMPP中运行代码时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ b SQLSTATE [HY000] [1045]用户'snipe_user'@'localhost'拒绝访问(使用密码:YES)
我的代码
C:\xampp\htdocs\GEOASSETS\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php line 55:
SQLSTATE[HY000] [1045] Access denied for user 'snipe_user'@'localhost' (using password: YES)
the code i have
<?php
namespace Illuminate\Database\Connectors;
use PDO;
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Database\DetectsLostConnections;
class Connector
{
use DetectsLostConnections;
/**
* The default PDO connection options.
*
* @var array
*/
protected $options = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
];
/**
* Get the PDO options based on the configuration.
*
* @param array $config
* @return array
*/
public function getOptions(array $config)
{
$options = Arr::get($config, 'options', []);
return array_diff_key($this->options, $options) + $options;
}
/**
* Create a new PDO connection.
*
* @param string $dsn
* @param array $config
* @param array $options
* @return \PDO
*/
public function createConnection($dsn, array $config, array $options)
{
$username = Arr::get($config, 'username');
$password = Arr::get($config, 'password');
try {
$pdo = new PDO($dsn, $username, $password, $options);
} catch (Exception $e) {
$pdo = $this->tryAgainIfCausedByLostConnection(
$e, $dsn, $username, $password, $options
);
}
return $pdo;
}
/**
* Get the default PDO connection options.
*
* @return array
*/
public function getDefaultOptions()
{
return $this->options;
}
/**
* Set the default PDO connection options.
*
* @param array $options
* @return void
*/
public function setDefaultOptions(array $options)
{
$this->options = $options;
}
/**
* Handle a exception that occurred during connect execution.
*
* @param \Exception $e
* @param string $dsn
* @param string $username
* @param string $password
* @param array $options
* @return \PDO
*
* @throws \Exception
*/
protected function tryAgainIfCausedByLostConnection(Exception $e, $dsn, $username, $password, $options)
{
if ($this->causedByLostConnection($e)) {
return new PDO($dsn, $username, $password, $options);
}
throw $e;
}
}
我的尝试:
What I have tried:
public function createConnection($dsn, array $config, array $options)
{
$username = Arr::get($config, 'username');
$password = Arr::get($config, 'password');
try {
$pdo = new PDO($dsn, $username, $password, $options);
} catch (Exception $e) {
$pdo = $this->tryAgainIfCausedByLostConnection(
$e, $dsn, $username, $password, $options
);
}
return $pdo;
}
推荐答案
options = [
PDO :: ATTR_CASE => PDO :: CASE_NATURAL,
PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION,
PDO :: ATTR_ORACLE_NULLS => PDO :: NULL_NATURAL,
PDO :: ATTR_STRINGIFY_FETCHES => false,
PDO :: ATTR_EMULATE_PREPARES => false,
];
/ * *
*根据配置获取PDO选项。
*
* @param数组
options = [ PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, ]; /** * Get the PDO options based on the configuration. * * @param array
config
* @return数组
* /
公共函数getOptions (array
config * @return array */ public function getOptions(array
config)
{
config) {
这篇关于在XAMPP中运行代码时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文