[英]I'm trying to connect to mysql database with php, but it gives me an error
I'm using Jetbrains and Mysql to work on this practical project, but when I connect to the mysql database it gives me the following error:我正在使用 Jetbrains 和 Mysql 来处理这个实际项目,但是当我连接到 mysql 数据库时,它给了我以下错误:
C:\wamp64\bin\php\php5.6.40\php.exe C:\wamp64\www\Social_Network\Includes\connection.php
Connection failed: SQLSTATE[HY000] [1049] Unknown database 'social_network'
Process finished with exit code 0
I made sure several times that the database name is the same name and there are no spelling errors at all (I copy pasted it from the database)我多次确保数据库名称是相同的名称并且根本没有拼写错误(我从数据库中复制粘贴它)
Here's my code:这是我的代码:
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$servername;dbname=social_network", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
//?>
Welll, there's little that can be done about it.好吧,对此无能为力。 MySQL thinks that the database does not exist .
MySQL 认为数据库不存在。
Actually, JetBrains PHPStorm has a SQL terminal utility that can diagnose the connection.实际上,JetBrains PHPStorm 有一个 SQL 终端实用程序可以诊断连接。 You may want to use it (once it knows what database you're connecting to, it will also warn you of several possible errors such as using the wrong table name or column name).
您可能想要使用它(一旦它知道您要连接的数据库,它还会警告您几个可能的错误,例如使用错误的表名或列名)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.