SeenGee Posted May 6, 2003 Share Posted May 6, 2003 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:1:30cb00a3ff] <?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\" ?>rn\"; $_xml .=\"<!-- table users -->\"; $_xml .=\"<users>rn\"; $result = mysql_query (\"select * from users\", $link); while ($row = mysql_fetch_object($result)) { $count = 0; $_xml .=\" <record>rn\"; foreach ($row as $data) { $_xml .=\" <$fieldnames[$count]>$data</$fieldnames[$count]>rn\"; $count++; } $_xml .=\" </record>rn\"; } $_xml .=\"</users>\"; fwrite($file, $_xml); fclose($file); echo $_xml; mysql_close ($link); ?> [/php:1:30cb00a3ff] ------------------------------------------------------------------------------ MY AMENDED SCRIPT FOR POSTGRES [php:1:30cb00a3ff] <?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\" ?>rn\"; $_xml .=\"<!-- table users -->\"; $_xml .=\"<users>rn\"; $result_set = pg_Exec ($conn, $sql); for ($j=0; $j<$rows; $j++) { $row = pg_fetch_object($result, $row) } $_xml .=\" <record>rn\"; foreach ($row as $data) { $_xml .=\" <$fieldnames[$count]>$data</$fieldnames[$count]>rn\"; $count++; } $_xml .=\" </record>rn\"; } $_xml .=\"</users>\"; fwrite($file, $_xml); fclose($file); echo $_xml; pg_close(); ?> [/php:1:30cb00a3ff] Thanks for helping. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.