[英]Connecting to AWS RDS database using beanstalk and PHP
In PHP 7, As I try to connect to the Beanstalk I have set up, I receive the error: 在PHP 7中,当我尝试连接到已设置的Beanstalk时,收到错误消息:
Fatal error: Uncaught Error: Class 'mysql' not found in C:\\Apache24\\htdocs\\php_file.php, Stack trace: #0 {main} thrown in C:\\Apache24\\htdocs\\php_file.php on line 41.
致命错误:未捕获错误:在C:\\ Apache24 \\ htdocs \\ php_file.php中找不到类'mysql',堆栈跟踪:在第41行的C:\\ Apache24 \\ htdocs \\ php_file.php中抛出了#0 {main}。
This server uses AWS RDS running MYSQL, and I am using apache 2.4 to localhost (for testing). 该服务器使用运行MYSQL的AWS RDS,并且我正在使用apache 2.4到localhost(用于测试)。
The code I'm using is: 我使用的代码是:
$servername = "MY BEANSTALK CONNECTION";
$username = "Username";
$password = "PSSWD";
$dbname = "DBNAME";
$conn = new mysql($servername, $username, $password, $dbname);
$sql = "SELECT * FROM column";
$result = $conn->query($sql);
$conn->close();
My updated code uses mysqli, but is still getting the same error. 我更新的代码使用mysqli,但仍然出现相同的错误。
From PHP documentation mysql
class is deprecated since version 5.5 and removed in version 7. that's why you're receiving the class not found error. 从PHP文档开始,从5.5版开始不推荐使用
mysql
类,而在7版中将其删除。这就是为什么您收到未找到类的错误的原因。
Try using mysqli
. 尝试使用
mysqli
。 The PHP documentation has good examples on this. PHP文档对此提供了很好的示例。 Look at example 2. I've pasted part of the example in this post for you.
看示例2。我已为您粘贴了示例中的一部分。 https://www.php.net/manual/en/function.mysql-connect.php
https://www.php.net/manual/zh/function.mysql-connect.php
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
$res = $mysqli->query("SELECT 'choices to please everybody.' AS _msg FROM DUAL");
$row = $res->fetch_assoc();
echo $row['_msg'];
?>
改用mysql_connect($ servername,$ username,$ password)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.