PHP, Failed connecting to database

OussamaMater

I can't connect to my databases, whenever i try it's giving me this error enter image description here

I tried to connect to the default databases like mysql, and it worked fine just like the pic shows enter image description here

I'm using wamp server the latest version, here's code if needed :

$servername = "localhost";
$username = "root";
$password = "";
$my_db="mydb";

$link=mysqli_connect($servername, $username, $password, $my_db);
if (mysqli_connect_error()) {
    die("there is an error");
} else {
    echo "connected to ".$my_db;
}
Dlk

Wampserver 3.2.0 new instalation or upgrading

This might help others

Probably xamp using mariaDB as default too.

Wamp server comes with mariaDB and mysql, and instaling mariaDB as default on 3306 port.

To make mysql work!

On instalation it asks to use mariaDB or MySql, mariaDB is checked as default and you cant change it, check mysql option and install.

when instalation done both will be runing mariaDB on default port and mysql on another port.

Right click on wamp icon where its runing should be on right bottom corner, goto tools and see your mysql runing port.

And include in your database connection same as folowng :

$host = 'localhost';
$db   = 'test';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
$port = '3308';

$dsn = "mysql:host=$host;dbname=$db;port=$port;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
try {
     $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
     throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

Note : I am using pdo.

See here for more : https://sourceforge.net/projects/wampserver/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Login failed while connecting to database

Connecting the Login page with database failed

connecting php to mssql database

Connecting to database with PDO in php

PHP Syntax - Connecting to Database

Php not connecting to a database

Error Connecting to database with PHP

PHP database not connecting

Connecting to a database in SQL and PHP

Connecting remote database server in Rails app failed

Application deployment failed when connecting with the database

Connecting to UCSC Genome MYSQL : "Failed to connect to database"

PHP not connecting to database for email and password

Error Connecting to Database via PHP

Connecting to Memgraph database from PHP

PHP error when connecting to MySQL database

Connecting to a specific database using php (xampp / mysql)

connecting two different database using php/mysql

Connecting to the MySQL Database using Dependency Injection in PHP

Connecting to AWS RDS database using beanstalk and PHP

Failed to configure a DataSource: Intellij Error when connecting Database to Spring Application

Auth failed, code 18 when connecting to MongoLab database

Error when connecting to a SQL database: Cannot open database "Students.mdf" requested by the login. The login failed

PHP - Connecting to heroku PostGres database from localhost (on Windows)

Why is my php code not connecting to my remote MySql database?

Connecting to a server-side SQL database via php with jquery

Webservice connecting do database with IOS, PHP, REST API, JSON

connecting to MS access with php when defined password for database

Connecting to Oracle Database 11g using PHP code

TOP Ranking

HotTag

Archive