i'm in the process of porting a script between mysql and postgres that writes to an xml file. thanks to some help on this forum i've made most of the transitions i need in terms of functions i think but the script is still not working correctly. would appreciate any help people can give me to complete this transition.
ORIGINAL SCRIPT FOR MYSQL
<?php
$link = mysql_connect ("localhost", "administrator", "password");
mysql_select_db("IAD", $link);
$_xml = ( bool ) false;
$result = mysql_query ("describe users", $link);
$count = 0;
while ($row = mysql_fetch_array($result)) {
$fieldnames[$count] = $row[0];
$count++;
}
$file= fopen("user.xml" , "w");
$_xml .="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\r\n";
$_xml .="<!-- table users -->";
$_xml .="<users>\r\n";
$result = mysql_query ("select * from users", $link);
while ($row = mysql_fetch_object($result)) {
$count = 0;
$_xml .=" <record>\r\n";
foreach ($row as $data) {
$_xml .=" <$fieldnames[$count]>$data</$fieldnames[$count]>\r\n";
$count++;
}
$_xml .=" </record>\r\n";
}
$_xml .="</users>";
fwrite($file, $_xml);
fclose($file);
echo $_xml;
mysql_close ($link);
?>
MY AMENDED SCRIPT FOR POSTGRES
<?php
$conn = pg_connect("host= user= password='' dbname=");
if (!$conn)
{
echo "<h1>Connection Error</h1>";
exit;
}
$sql="SELECT * FROM user;";
$result_set = pg_Exec ($conn, $sql);
for ($j=0; $j<$rows; $j++)
{
list($user_id,$user_location) = pg_fetch_row($result_set, $j);
}
$file= fopen("user.xml" , "w");
$_xml .="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\r\n";
$_xml .="<!-- table users -->";
$_xml .="<users>\r\n";
$result_set = pg_Exec ($conn, $sql);
for ($j=0; $j<$rows; $j++)
{
$row = pg_fetch_object($result, $row)
}
$_xml .=" <record>\r\n";
foreach ($row as $data)
{
$_xml .=" <$fieldnames[$count]>$data</$fieldnames[$count]>\r\n";
$count++;
}
$_xml .=" </record>\r\n";
}
$_xml .="</users>";
fwrite($file, $_xml);
fclose($file);
echo $_xml;
pg_close();
?>
Thanks for helping.
THIS IS THE PROBLEM I GET:
gettin this parse error:
Parse error: parse error in /../newCheck.php on line 28
line 28 being the line underneath
$row = pg_fetch_object($result, $row)
Probably somethink in the way i have ported the code from mysql.
Thanks.