[英]PHP - Cannot connect to mysql on aws ec2
I am able to connect to the mysql server from the terminal on my local system but cannot connect to it from my php code. 我能够从本地系统上的终端连接到mysql服务器,但是无法从我的php代码连接到它。
<!-- Establish conenction to sql -->
<?php
session_start();
$servername = "ec2-xxxx.compute-1.amazonaws.com";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection, the code hangs on this line
$conn = new mysqli($servername, $username, $password, $dbname);
?>
The code seems to hang on the 'new sqli' line. 该代码似乎挂在“新sqli”行上。 I tried placing it inside a try-catch block, but the catch block is never executed.
我尝试将其放置在try-catch块中,但是catch块从未执行。 Nothing gets executed beyond that line.
在那条线之外什么也不会执行。
Edit: Dipti suggest that I place ini_set('display_errors', 1); 编辑:Dipti建议我放置ini_set('display_errors',1); on top on the php file.
在php文件的顶部。 This gave me an output saying that mysqli couldn't be found.
这给了我一个输出,说找不到mysqli。 Doing a "sudo apt install php-mysql" fixed the issue.
进行“ sudo apt安装php-mysql”解决了该问题。
您使用sql
server连接,并且server name
应为localhost
而不是Amazon链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.