我在网站上看到了这个错误。
不推荐使用:mysql_query():不推荐使用mysql扩展名 将来删除:使用mysqli或PDO代替 第3行/home/u857740002/public_html/datafetch.php
不推荐使用:mysql_query():不推荐使用mysql扩展名 将来删除:使用mysqli或PDO代替 第23行/home/u857740002/public_html/datafetch.php
我正在使用此代码。
任何人都可以纠正这两行。
$siteSettings = mysql_query("select * from pu_settings where sid = '1' ");
$siteSoft = mysql_query("select * from pu_softwares where slug = '$slug' ");
答案 0 :(得分:3)
MySQL_ *已被弃用,很快就会被PHP删除。使用MySQLi_ *。 请参阅:AST
请改用:
$link = mysqli_connect([dbhost],[dbusername],[dbpass],[dbname]);
$siteSettings = mysqli_query($link,"select * from pu_settings where sid = '1' ");
$siteSoft = mysqli_query($link,"select * from pu_softwares where slug = '$slug' ");
答案 1 :(得分:2)
mysql_*
已弃用+已移除库,因此请使用mysqli_*
或PDO
: -
假设您的数据库连接对象为$conn
$siteSettings = mysqli_query($conn,"select * from pu_settings where sid = '1' ")or die(mysqli_error($conn));
$siteSoft = mysql_query($conn,"select * from pu_softwares where slug = '$slug' ")or die(mysqli_error($conn));
使用mysqli_*
创建连接的代码是: -
$conn=mysqli_connect("hostname","username","password","databasename");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
答案 2 :(得分:1)
在查询中使用mysqli_*
代替mysql_*
。
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$siteSettings = mysqli_query($con,"select * from pu_settings where sid = '1' ");
$siteSoft = mysqli_query($con,"select * from pu_softwares where slug = '$slug' ");