Jump to content

Between mysql and psql


SeenGee

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.