gpt4 book ai didi

php - MySQL 的本地主机错误

转载 作者:行者123 更新时间:2023-11-29 12:38:49 26 4
gpt4 key购买 nike

这个错误是什么意思?

"Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\Myren\Connections\localhost.php on line"?

最佳答案

“这个错误是什么意思?”

"Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\Myren\Connections\localhost.php on line"?

  • 安装时Wampserver ,它目前附带 PHP 版本 5.5.12,如果使用基于 mysql_ 的代码,该版本的 PHP 将抛出该通知。

  • 您需要将 mysql_ 的所有实例更改为 mysqli_(或使用 PDO )。

旁注: mysqli_需要传递DB连接参数。

我知道这一点是因为我自己最近在我的一台 PC 上安装了 Wampserver,并且在运行安装中包含的测试 SQL 脚本时收到了相同的错误消息。已经知道错误是什么,很快就能纠正问题。

因此,例如:(更改以下内容)...

<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'username', 'password_if_any')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('your_database') or die('Could not select database');

// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

需要更改为:

<?php
// Connecting, selecting database
$link = mysqli_connect('localhost', 'username', 'password_if_any', 'your_DB')
or die('Could not connect: ' . mysqli_error($link));
echo 'Connected successfully';

// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysqli_query($link, $query)
or die('Query failed: ' . mysqli_error($link));

// Printing results in HTML
echo "<table>\n";
while ($line = mysqli_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysqli_free_result($result);

// Closing connection
mysqli_close($link);
?>

关于php - MySQL 的本地主机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26401492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com