得到这个错误家伙“无法选择数据库名称”我是 PHP 新手,我正在学习。我正在创建一个 php 脚本,它将从我的数据库生成 XML 提要。这是代码:
<?php
$dbhost = "localhost";
$dbuser = "my database username";
$dbpass = "my password";
$dbname = "my database name";
$dbhandle = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("dbname",$dbhandle)
or die("Could not select databasename");
$sql = "SELECT * FROM listings";
$q = mysql_query($sql) or die(mysql_error());
$xml = "<listings>";
while($r = mysql_fetch_array($q)){
$xml .= "<listings>";
$xml .= "<listingsdb_title>".$r['listingsdb_title']."</listingsdb_title>";
$xml .= "<address>".$r['address']."</address>";
$xml .= "<class_name>".$r['class_name']."</class_name>";
$xml .= "<listingsimages_thumb_file_name>".$r['listingsimages_thumb_file_name']." </listingsimages_thumb_file_name>";
$xml .= "<beds>".$r['beds']."</beds>";
$xml .= "<baths>".$r['baths']."</baths>";
$xml .= "<sqm>".$r['sqm']."</sqm>";
$xml .= "<author>".$r['author']."</author>";
$xml .= "<full_desc>".$r['full_desc']."</full_desc>";
$xml .= "<price>".$r['price']."</price>";
$xml .= "</listings>";
}
$xml .= "</listings>";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("listings.xml");
?>