W
W
WantToKnowWhatIsWebDev2017-01-26 18:30:37
PHP
WantToKnowWhatIsWebDev, 2017-01-26 18:30:37

(PDO) Error connecting to MySQL?

The code itself

<?php

$host = "vh44.timeweb.ru"; (локалхост пробовал)
$db = "users";
$user = "cv41923_fartu";
$pass = "mypassword";
$charset = "utf8";

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn, $user, $pass, $opt);

No errors, it just says: The sitename site cannot process this request yet.
What is the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2017-01-26
@WantToKnowWhatIsWebDev

1) Look at the logs, everything that happens on the servers of hosters is usually accompanied by a bunch of logs, in this case, PHP logs should help.
2) In the hosting panel, in the database settings, data for the connection is usually indicated, perhaps you have a non-standard connection port or some other tricks from the hoster. See the settings in the panel.
3) If the hosting allows - turn on the output of errors and warnings, this will greatly simplify the installation and configuration work.
PS: as a completely crazy option - pdo is not included in the list of php extensions for this hosting, if there are php settings there - check, but this should be visible from the logs.

A
A person from Kazakhstan, 2017-01-26
@LenovoId

and if you specify the full path to the host?
i.e. from http://

W
WantToKnowWhatIsWebDev, 2017-01-26
@WantToKnowWhatIsWebDev

Is the syntax correct?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question