Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Making SQl data into a xml file and saving file

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Making SQl data into a xml file and saving file

Postby jimdac59 » Tue Apr 09, 2013 6:21 pm

Hi all
Firstly, I am new at this so I hope I dont offend anyone with my lack of knowledge, but still trying to learn from everyone
Now, I would like to be able to run a function that would go through a certain table in the database and turn the fields into an xml and then save that file to a certain area
Currently I have the following code.
the error log show this. I believe that I have coded mysql_ fetch statement correctly (but it seems I have not)

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Complaints\ConsultantUpdate.php on line 13

Warning: file_put_contents(C:\wamp\www\Complaints\) [function.file-put-contents]: failed to open stream: No such file or directory in C:\wamp\www\Complaints\ConsultantUpdate.php on line 28


<?php require_once("Includes/connection.php"); ?>
<?php require_once("Includes/functions.php"); ?>

<?php

$sqlGetConsultant = "SELECT * from cssu order by Employid";


$string = '<Staff><Staff>';

while ($row = mysql_fetch_array($sqlGetConsultant)) {
$id=$row['Employid'];
$FirstName=$row['FirstName'];
$LastName=$row['LastName'];

$string .='<Employid>'.$id.'</Employid>';
$string .='<Firstname>'.$FirstName.'</FirstName>';
$string .='<LastName>'.$LastName.'</LastName>';
}
$string .='</Staff></Staff>';
$xml = new SimpleXMLElement($string);


$filename= 'C:\\wamp\www\Complaints\\';
file_put_contents($filename ,$xml);


?>
Any help would be much appreciated.
Again pls talk slow as I am very new at this.....lol
Thanks in advance
Jim
jimdac59
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Apr 09, 2013 1:08 am

Re: Making SQl data into a xml file and saving file

Postby jimdac59 » Thu Apr 11, 2013 4:24 pm

Hi to all again
Does anyone have a suggestion on what I am doing wrong. Any help would be appreciated

Cheers
Jim
jimdac59
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Apr 09, 2013 1:08 am

Re: Making SQl data into a xml file and saving file

Postby seandisanti » Wed Apr 17, 2013 3:14 pm

a few things you're doing wrong at a glance.
1) posting to the wrong forum, this one is for posting finished scripts, not necessarily getting help with problems,
2) using mysql_ functions. They are officially deprecated as of 5.5 and will be removed in a future version. PDO is more secure, faster, and easy to implement.
3) check out fopen() and file_exists(), etc on php.net to see how to properly implement file I/O
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron