简体   繁体   中英

Database connection Unknown error in PHP with MySQL server workbench not in phpmyadmin

I`m working on a java swing app. so that i have created a database called c_app in MySQL server workbench. what i need is to fetch data into a HTML page using PHP.

$username = "root";
$password = "";
$hostname = "localhost:3307";
$db = "c_app";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $db)
or die("Unable to connect to MySQL");

This code segment gives me Warning: mysqli_connect(): (HY000/1049): Unknown database 'c_app' in C:\\xampp\\htdocs\\C_AppWeb\\linkpage.php on line 7 Unable to connect to MySQL

What is the problem here? do i need phpmyadmin database rather than MySQl database? can anyone help me?

First one, both phpmyadmin and workbench are not database. They are tools to work with database.

I see you use port 3307 in your code, so let you try:

$username = "root";
$password = "";
$hostname = "localhost";
$port = 3307;
$db = "c_app";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $db, $port)
or die("Unable to connect to MySQL");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM