Salute people, krch doesn’t want to connect …
mysql.php
& lt ;?
class Mysql {
private $ db;
private $ config;
public function __construct () {
$ this- & gt; config = include __DIR__. '/ config.php';
$ this- & gt; db = new PDO ("mysql: dbname = {$ this- & gt; config ['dbname']}; host = {$ this- & gt; config ['dbhost']}, {$ this- & gt ; config ['dbuser']}, {$ this- & gt; config ['dbpassword']} ");
}
function query ($ sql, $ params = [])
{
$ sth - $ this- & gt; db- & gt; prepare ($ sql);
$ sth = $ sth- & gt; execute ($ params);
return $ sth- & gt; fetchAll ();
}
}
This error is displayed when I create a class:
Warning: PDO :: __ construct (): php_network_getaddresses: getaddrinfo failed: . in E: \ OpenServer \ OpenServer \ domains \ blackmarket \ core \ mysql.php on line 9
Fatal error: in
E: \ OpenServer \ OpenServer \ domains \ blackmarket \ core \ mysql.php on line 9
Answer 1, authority 100%
First of all, it is worth checking whether the host specified in the settings is available for connection. Check its availability using the ping
and nslookup
commands. If the hostname is a domain name, try specifying an IP address instead.
Based on the answer to the question:
PHP error: php_network_getaddresses: getaddrinfo failed: (while getting information from other site.)
UPDATED
You have an error on this line (there is an error in the $ dsn
parameter):
$ this- & gt; db = new PDO ("mysql: dbname = {$ this- & gt; config ['dbname' ]}; host = {$ this- & gt; config ['dbhost']}, {$ this- & gt; config ['dbuser']}, {$ this- & gt; config ['dbpassword']} ");
Correct like this:
$ this- & gt; db = new PDO ("mysql: dbname = {$ this- & gt; config ['dbname' ]}; host = {$ this- & gt; config ['dbhost']} ", $ this- & gt; config ['dbuser'], $ this- & gt; config ['dbpassword']);