gpt4 book ai didi

php - 将mysql更改为mysqli错误

转载 作者:行者123 更新时间:2023-11-29 23:50:00 25 4
gpt4 key购买 nike

您好,我很难让此代码在运行PHP 5.5的服务器上运行
代码来自www.ip2nation.com

<?php

$server = ''; // MySQL hostname
$username = ''; // MySQL username
$password = ''; // MySQL password
$dbname = ''; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName) = mysql_fetch_row(mysql_query($sql));

// Output full country name
echo $countryName;


?>

运行代码时出现错误,例如:

PHP Parse error:  syntax error, unexpected ''.$_SERVER['' (T_CONSTANT_ENCAPSED_STRING) in /test1.php on line 14


任何帮助将不胜感激!谢谢

最佳答案

尝试这个

$db = mysqli_connect($server, $username, $password) or die(mysqli_error($db));
mysqli_select_db($db,$dbname) or die(mysqli_error($db));

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName) = mysqli_fetch_row(mysqli_query($db,$sql));

// Output full country name
echo $countryName;

关于php - 将mysql更改为mysqli错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25697501/

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