mysql_fetch_assoc()到odbc [英] mysql_fetch_assoc() to odbc
本文介绍了mysql_fetch_assoc()到odbc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码为数据库中的表创建一个xml文件
i have this code to create an xml file for a table in a database
<?php
//database configuration
$config['mysql_host'] = "localhost";
$config['mysql_user'] = "root";
$config['mysql_pass'] = "";
$config['db_name'] = "shop";
$config['table_name'] = "category";
$file=fopen("phptoxml.xml","w");
//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \r\n";
$root_element = $config['table_name']."s";
$xml .= "<$root_element> \r\n";
//select all items in table
$sql = "SELECT * FROM ".$config['table_name'];
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result)>0)
{
while($result_array = mysql_fetch_assoc($result))
{
$xml .= "<".$config['table_name']."> ";
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= "<$key>";
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= "<![CDATA[$value";
//and close the element
$xml .= "</$key> ";
}
$xml.="</".$config['table_name'].">";
}
}
//close the root element
$xml .= "</$root_element> ";
//send the xml header to the browser
header ("Content-Type:text/xml");
//output the XML data
echo $xml;
fwrite($file, $xml);
fclose($file);
?>
i希望将其转换为使用odbc在访问数据库上使用它但我不知道如何替换mysql_fetch_assoc()以使其适用于odbc :(:(
i want to convert it to use it on an access database using odbc but i dont know how to replace mysql_fetch_assoc() to make it work for odbc :( :(
推荐答案
config [' mysql_host'] = localhost;
config['mysql_host'] = "localhost";
config [' mysql_user'] = root ;
config['mysql_user'] = "root";
config [' mysql_pass'] = ;
config['mysql_pass'] = "";
这篇关于mysql_fetch_assoc()到odbc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文