H
H
Huntgold2022-01-17 00:20:14
PHP
Huntgold, 2022-01-17 00:20:14

How to connect to Open Server DB via PHP?

When I go to PHP Adminer, I log in with the data below without any problems. The script itself for some reason does not want to connect to the Open Server database. How to decide?

<?php
$host = 'localhost';
$db   = 'u14215_default';
$user = 'root';
$pass = 'admin';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
    PDO::ATTR_PERSISTENT         => true,
];
$pdo = new PDO($dsn, $user, $pass, $opt);

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2022-01-17
@FanatPHP

61cd1515315b8585107266.jpg
If it is not possible to copy the database access data without errors, then in this case PHP will take the handle and tell you what is wrong. You just need to read the error message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question