我写了这段代码,但是 stackoverflow 上的人指出这些函数将被弃用。所以我用 mysqli 函数更新它。新的不会返回我想显示的图像 url。
这是旧的工作代码:
<html>
<head>
<title>My first PHP script</title>
</head>
<body>
<?php
$dbhost = 'access.website';
$dbname = 'my_db';
$dbuser = 'usr_nam';
$dbpass = 'passwrd';
$mysql_handle = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Error Connecting To Database Server");
mysql_select_db($dbname, $mysql_handle)
or die("Error selecting database: $dbname");
$query = sprintf("SELECT image_url, Type FROM Pokemon
c WHERE c.name='%s'",
mysql_real_escape_string($_GET["fname"]));
$result = mysql_fetch_assoc(mysql_query($query));
echo '<img height="450" width="330" src="'.$result['image_url'].'" />';
mysql_close($mysql_handle);
?>
</body>
</html>
这是我的新代码:
<html>
<head>
<title>My first PHP script</title>
</head>
<body>
<?php
$dbhost = 'access.website';
$dbname = 'my_db';
$dbuser = 'usr_nam';
$dbpass = 'passwrd';
$link = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
mysqli_select_db($link,$dbname);
$query = sprintf("SELECT image_url, Type FROM Pokemon
c WHERE c.name='%s'",
mysqli_real_escape_string($link,$_GET["fname"]));
$result = mysqli_query($link,$query);
echo '<img height="450" width="330" src="'.$result['image_url'].'" />';
mysqli_close($link);
?>
</body>
</html>