• About
  • Archives
  • Categories
  • Using Eclipse as a PHP IDE in Ubuntu 9.10

    2009 - 11.25

    This is actually much easier than any of the guides I found online make out.

    Firstly, install Eclipse from the repositories. Then open it up, select your default workspace (if you havent already) and then:

    1. From the Help menu, select “Install new software”.
    2. Click the “Add” button and add the following:
        • Name: Eclipse Updates (Galileo)
        • Location: http://download.eclipse.org/releases/galileo/
        1. Apply your changes and wait for the contents to download.
        2. When all is ready, select your new source from the drop down and look for the “Programming languages” section.
        3. Open it up and add the “PHP Development Tools (PDT) SDK Feature”.
        4. Step through using Next and Finish etc, and after a few moments downloading and installing you now have a PHP ready IDE.
        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Loading JSON data – the EASY way!

        2009 - 11.18

        json160A few weeks ago I wrote a blog post about using jQuery and JSON to automatically load data from a JSON file in to name-matched controls on an HTML page.

        It is only now that I realise quite how powerful this is!

        The great thing about it is that you do not have to edit your data-load function if you add a new field to the database. Because the jQuery function loops through all the fields in the JSON data, it will automatically insert the values in to the correct fields, providing those fields are named the same as the html form controls.

        Here is the code again for those who dont want to check back.

        $.getJSON("/yourJson.js, function(myJson){
        	$.each(myJson.rows, function(i,item) {
        		 for (prop in item) {
        		 	 $('#' + prop).val(item[prop]);
        		 }
        	});
        });
        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Installing MyODBC 3.51 on Windows 7 x64

        2009 - 11.16

        mysql2In order to get some of our 32 bit applications working on Windows 7 64 bit edition, we need to provide support for the MySQL 3.51 ODBC connector.

        This is actually quite simple to do, as long as you know what to look for. The ODBC manager that you are able to access from within Windows is not going to work for you, but it turns out that Microsoft provide a 32 bit manager that will.

        To use this manager, run the following command:

        c:\windows\syswow64\odbcad32.exe

        Please note that it is not good enough to just type odbcad32.exe, as there is another file in the path with the same file name (great work MS!). However, once you have opened this application up, it works in the exact same way as if you were running XP.

        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Setting up a basic web server using Ubuntu 9.10 (Desktop)

        2009 - 11.12

        Ubuntu LogoI have been using Ubuntu 9.10 for a while and wanted to see how it performs as a web server. The GUI interface is very slick and it is an ideal OS for beginners and advanced users alike. I suspect that many people will want to use it as the basis for their webservers.

        I suggest creating a virtual machine with something like VirtualBox for this. It is much more flexible that way, and you can move it to a more powerful machine if you decide you need to.

        Phase 1. Install required applications:

        1. Open ‘Synaptic package manager’ from the System/Administration menu.
        2. Click the ‘Search’ button.
        3. Enter ‘Apache’ and press return.
        4. You will see an item called ‘Apache2′ in the list of results. Click the box to the left to mark it as something you want to install.
        5. Repeat this process for:
          • Php5
          • MySql
          • Php5-mysql
        6. Click the ‘Apply’ button on the toolbar.
        7. This will start the installation process, during which you will be prompted to provide a password for the MySQL root account. Supply a strong password and make sure you do not forget it.
        8. It worked!When everything has finished installing, I suggest rebooting. There are ways of starting the servers without rebooting, but a reboot works just as well and is much easier.
        9. After you have logged back in to Ubuntu, open up Firefox and visit http://localhost.
        10. You should see a page that says “It works!” which means that your webserver is now working.

        Phase 2: Configure Virtual Hosts (So you can have more than one site on your server)

        I have chosen to use the command line to do much of this phase rather than the GUI. For me, it is much easier to access protected system files from the shell rather than use a GUI. However, should you want to use a GUI, you will need to be running with root privileges. You can do this by entering: sudo nautilus in to a command line (and enter your password). However, the instructions below are for using the shell.

        Any time you see the sudo command, that means that you will run the command as root (administrator). Linux is much more secure than Windows thanks to it being locked down by default with a standard set of permissions. It might seem like hassle to keep having to switch to be administrator but it makes things much safer. Deal with it!

        1. Open a new Terminal from Applications / Accessories in the menus.
        2. In the terminal, enter the following commands and review the results so you know what you are doing.
        3. cd /etc/apache2/sites-enabled (this moves you to the folder where you can define different websites)
        4. ls (lower case LS: this will show you a list of files)
        5. sudo cp 000-default 001-mysite (this will copy the default config file so you can use it as the basis for your new site)
        6. Enter your password when prompted (this should only happen once, but if you are prompted again – just re-enter it)
        7. sudo gedit 001-mysite (this will use the gedit text editor to open and allow you to edit the new site config file)
        8. Change the ServerAdmin row to use your email address. ie. ServerAdmin sam@mysite.net
        9. Add a row below with the tag: ServerName followed by the name of your site. I will continue to use mysite.local throughout. ie. ServerName mysite.local
        10. Edit the row DocumentRoot so that the new path is a sub-folder of www called 001-mysite. ie. /var/www/001-mysite
        11. Edit the row <Directory…> so that the new path is also used. ie. <Directory /var/www/001-mysite>
        12. Save the file and closed GEdit.
        13. A working PHP virtual hostWe now need to let your computer know that it IS mysite.local. The easiest way to do this is to edit your hosts file. There is plenty of information online about what this file does.
        14. From the terminal, type: sudo gedit /etc/hosts
        15. Add a new row below 127.0.0.1    localhost that reads: 127.0.0.1     mysite.local (spaces are tabs).
        16. Save the file and close GEdit.
        17. Now we need to create the file structure for where the sites files will live.
        18. Enter: sudo mkdir /var/www/001-mysite (this will create a new folder that will store your php/html files etc)
        19. cd /var/www/001-mysite
        20. sudo gedit index.php (this will open the text editor again and will allow you to create the index page for your site).
        21. In the text editor, enter the following bold text (including all the punctuation): <?php phpinfo(); ?>
        22. Save the file and close.
        23. sudo /etc/init.d/apache2 restart (this restarts the Apache service so that the new virtual host is available)
        24. Now open firefox and visit your new site: http://mysite.local
        25. You should see a whole load of information about your server, and more specifically about your PHP installation.
        26. Thats it! Repeat this phase to add as many virtual hosts as you like.

        You will now almost certainly want to secure your server. If you have got this far then you can at least get your site(s) up and running on your local machine. Ill cover securing your server in another post.

        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Charlie Sheen’s Questions

        2009 - 09.23

        North Tower explosionRecently, Charlie Sheen went on the record saying that he didn’t believe the official story of what happened in New York on 9/11. He hasn’t said what he thinks happened, he has just come up with a list of difficult questions that he (and millions of other people around the world) wants answered. He has posed the questions in a format that reads as 20 minutes with the President, where Charlie talks to Obama and lets him know about the questions.

        He has asked that anyone (press or otherwise) who can seriously dispute any of these points contacts him, or even goes live on any talk show to debate him. The gauntlet has officially been thrown…..

        Just to prove that this is Charlie Sheen, here is a link to a video of him discussing things.

        I have just copied the questions here – but you can read the full story at Prison Planet.

        20 Minutes With The President

        CS – Thank you Mr. President. Okay, first; On the FBI’s most wanted list Osama Bin Laden is not charged with the crimes of 911. When I called the FBI to ask them why this was the case, they replied: “There’s not enough evidence to link Bin Laden to the crime scene,” I later discovered he had never even been indicted by the D.O.J.

        CS – Number 2; FBI translator Sibel Edmonds, was dismissed and gagged by the D.O.J. after she revealed that the government had foreknowledge of plans to attack American cities using planes as bombs as early as April 2001. In July of ‘09, Mrs. Edmonds broke the Federal gag order and went public to reveal that Osama Bin Laden, Al Qaeda and the Taliban were all working for and with the C.I.A. up until the day of 9/11.

        CS – Number 3; The following is a quote from Mayor Giuliani during an interview on 9/11 with Peter Jennings for ABC News. “I went down to the scene and we set up headquarters at 75 Barkley Street, which was right there with the Police Commissioner, the Fire Commissioner, the Head of Emergency Management, and we were operating out of there when we were told that the World Trade Center was going to collapse. And it did collapse before we could actually get out of the building, so we were trapped in the building for 10, 15 minutes, and finally found an exit and got out, walked north, and took a lot of people with us.”

        WHO TOLD HIM THIS??? To this day, the answer to this question remains unanswered, completely ignored and emphatically DENIED by Mayor Giuliani on several public occasions.

        CS – Number 4; In April 2004, USA Today reported, “In the two years before the Sept. 11 attacks, the North American Aerospace Defense Command conducted exercises simulating what the White House says was unimaginable at the time: hijacked airliners used as weapons to crash into targets and cause mass casualties.” One of the targets was the World Trade Center.

        CS – Number 5; On September 12th 2007, CNN’s ‘Anderson Cooper 360’, reported that the mysterious “white plane” spotted and videotaped by multiple media outlets, flying in restricted airspace over the White House shortly before 10am on the morning of 9/11, was in fact the Air Force’s E-4B, a specially modified Boeing 747 with a communications pod behind the cockpit; otherwise known as “The Doomsday Plane”.

        Though fully aware of the event, the 9/11 Commission did not deem the appearance of the military plane to be of any interest and did not include it in the final 9/11 Commission report.

        CS – Number 6; Three F-16s assigned to Andrews Air Force Base, ten miles from Washington, DC, are conducting training exercises in North Carolina 207 miles away as the first plane crashes into the WTC. Even at significantly less than their top speed of 1500 mph, they could still have defended the skies over Washington well before 9am, more than 37 minutes before Flight 77 crashes into the Pentagon, however, they did not return until after 9:55am.

        Andrews AFB had no armed fighters on alert and ready to take off on the morning of 9/11.

        CS – Number 7; WTC Building 7. Watch the video of its collapse.

        CS – Number 8; Flight 93 is fourth plane to crash on 9/11 at 10:03am. V.P. Cheney only gives shoot down order at 10:10-10:20am and this is not communicated to NORAD until 28 minutes after Flight 93 has crashed.

        Fueling further suspicion on this front is the fact that three months before the attacks of 9/11, Dick Cheney usurped control of NORAD, and therefore he, and no one else on planet Earth, had the power to call for military sorties on the hijacked airliners on 9/11. He did not exercise that power. Three months after 9/11, he relinquished command of NORAD and returned it to military operation.

        CS – Number 9; Scores of main stream news outlets reported that the F.B.I. conducted an investigation of at least FIVE of the 9/11 hijackers being trained at U.S. military flight schools. Those investigations are now sealed and need to be declassified.

        CS – Number 10; In 2004, New York firefighters Mike Bellone and Nicholas DeMasi went public to say they had found the black boxes at the World Trade Center, but were told to keep their mouths shut by FBI agents. Nicholas DeMasi said that he escorted federal agents on an all-terrain vehicle in October 2001 and helped them locate the devices, a story backed up by rescue volunteer Mike Bellone.

        As the Philadelphia Daily News reported at the time, “Their story raises the question of whether there was a some type of cover-up at Ground Zero.”

        CS – Number 11 – Hundreds of eye witnesses including first responders, fire captains, news reporters, and police, all described multiple explosions in both towers before and during the collapse.

        CS – Number 12; An astounding video uncovered from the archives shows BBC News correspondent Jane Standley reporting on the collapse of WTC Building 7 over twenty minutes before it fell at 5:20pm on the afternoon of 9/11. Tapes from earlier BBC broadcasts show news anchors discussing the collapse of WTC 7 a full 26 minutes in advance. The BBC at first claimed that their tapes from 9/11 had been “lost” before admitting that they made the “error” of reporting the collapse of WTC 7 before it happened without adequately explaining how they could have obtained advance knowledge of the event.

        In addition, over an hour before the collapse of WTC 7, at 4:10pm, CNN’s Aaron Brown reported that the building “has either collapsed, or is collapsing.”

        CS – Number 13; Solicitor General Ted Olson’s claim that his wife Barbara Olsen called him twice from Flight 77, describing hijackers with box cutters, was a central plank of the official 9/11 story.

        However, the credibility of the story was completely undermined after Olsen kept changing his story about whether his wife used her cell phone or the airplane phone. The technology to enable cell phone calls from high-altitude airline flights was not created until 2004. American Airlines confirmed that Flight 77 was a Boeing 757 and that this plane did not have airplane phones on board.

        According to the FBI, Barbara Olsen attempted to call her husband only once and the call failed to connect, therefore Olsen must have been lying when he claimed he had spoken to his wife from Flight 77.

        CS – Number 14; The size of a Boeing 757 is approximately 125ft in width and yet images of the impact zone at the Pentagon supposedly caused by the crash merely show a hole no more than 16ft in diameter. The engines of the 757 would have punctured a hole bigger than this, never mind the whole plane. Images before the partial collapse of the impact zone show little real impact damage and a sparse debris field completely inconsistent with the crash of a large jetliner, especially when contrasted with other images showing airplane crashes into buildings.

        CS – Number 15; What is the meaning behind the following quote attributed to Dick Cheney which came to light during the 9/11 Commission hearings? The passage is taken from testimony given by then Secretary of Transportation Norman Mineta.

        During the time that the airplane was coming in to the Pentagon, there was a young man who would come in and say to the Vice President, “The plane is 50 miles out.” “The plane is 30 miles out.” And when it got down to “the plane is 10 miles out,” the young man also said to the Vice President, “Do the orders still stand?” And the Vice President turned and whipped his neck around and said, “Of course the orders still stand. Have you heard anything to the contrary?”

        As the plane was not shot down, in addition to the fact that armed fighter jets were nowhere near the plane and the Pentagon defensive system was not activated, are we to take it that the orders were to let the plane find its target?

        CS – Number 16; In May 2003, the Miami Herald reported how the Bush administration was refusing to release a 900-page congressional report on 9/11 because it wanted to “avoid enshrining embarrassing details in the report,” particularly regarding pre-9/11 warnings as well as the fact that the hijackers were trained at U.S. flight schools.

        CS – Number 17; Top Pentagon officials cancelled their scheduled flights for September 11th on September 10th. San Francisco Mayor Willie Brown, following a security warning, cancelled a flight into New York that was scheduled for the morning of 9/11.

        CS – Number 18; The technology to enable cell phone calls from high-altitude airline flights was not created until 2004, and even by that point it was only in the trial phase. Calls from cell phones which formed an integral part of the official government version of events were technologically impossible at the time.

        CS – Number 19: On April 29, 2004, President Bush and V.P. Cheney would only meet with the commission under specific clandestine conditions. They insisted on testifying together and not under oath. They also demanded that their testimony be treated as a matter of “state secret.” To date, nothing they spoke of that day exists in the public domain.

        CS – And finally Mr. President – Number 20; A few days after the attack, several newspapers as well as the FBI reported that a paper passport had been found in the ruins of the WTC. In August 2004, CNN reported that 9/11 hijacker Ziad Jarrah’s visa was found in the remains of Flight 93 which went down in Shanksville, Pennsylvania.

        At least a third of the WTC victim’s bodies were vaporized and many of the victims of the Pentagon incident were burned beyond recognition. And yet visas and paper passports which identify the perpetrators and back up the official version of events miraculously survive explosions and fires that we are told melted steel buildings.

        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Inserting JSON data in to name-matched controls

        2009 - 09.01

        Thought this might be handy… This loop will insert the values from a JSON object in to text boxes.

        It loops around each key-pair and inserts the value if there is a text box with an ID that matches the key name.

        This is the JSON data: (yourJson.js)

        {"page":1,"total":1,"records":1,"paging":20,"rows":[
        {"clipId":"14792","barcode":"02528","title":"My Project Sample","format":"DigiBeta","source":"1242",
        "runningTime":"14 Mins","location":"Library","timeCode":"10:00:00","cUser":"Sam",
        "cDate":"1 Jan 2007","mUser":"Sam","mDate":"1 Jan 2008"}]}

        This is the form HTML:

        <form>
        	<table>
        		<tr>
        			<th>Clip Id</th>
        			<td><input id='clipId'></td>
        		</tr>
        		<tr>
        			<th>Barcode</th>
        			<td><input id='barcode'></td>
        		</tr>
        		<tr>
        			<th>Title</th>
        			<td><input id='title'></td>
        		</tr>
        		<tr>
        			<th>Format</th>
        			<td><input id='format'></td>
        		</tr>
        		<tr>
        			<th>Source</th>
        			<td><input id='source'></td>
        		</tr>
        		<tr>
        			<th>Running Time</th>
        			<td><input id='runningTime'></td>
        		</tr>
        		<tr>
        			<th>Location</th>
        			<td><input id='location'></td>
        		</tr>
        		<tr>
        			<th>Time Code</th>
        			<td><input id='timeCode'></td>
        		</tr>
        	</table>
        </form>

        This is the jQuery:

        	$.getJSON("/yourJson.js, function(myJson){
        		$.each(myJson.rows, function(i,item) {
        		    for (prop in item) {
        				$('#' + prop).val(item[prop]);
        		    }
        		}); 
        	});
        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        HAR panel discussing copyright and file sharing

        2009 - 08.26

        An interesting discussion about file sharing for those interested in DRM, copyright and patents. Most people agree that the business model based around copyright no longer works in the digital age. The question is, what other options do we have, and how many people are going to get sued along the way?

        HAR panel from TorrentFreak on Vimeo.

        For information about HAR (Hacking at random) please see their website: https://wiki.har2009.org/

        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Creating JSON data from MySQL in PHP

        2009 - 08.24

        Here is a quick post that demonstrates how to create some neat JSON data from MySQL using PHP. The script is really simple, and has been working well for me over the last few weeks.

        If anything is confusing, it might be worth checking out the previous post about creating XML data from PHP. It explains things in more detail and will help if you are not familiar…

        //set up the php headers so that the page doesnt cache etc
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
        header("Content-type: text/json");
         
        $jsonArray->page = $page; 
        $jsonArray->total = $totalPages;
        $jsonArray->records = $recordCount; 
         
        $i=0; 
        while ($row = $db->fetch_array($countRows)) {
        	$jsonArray->rows[$i]['id']=$row['userAccountId']; 
        	$jsonArray->rows[$i]['userName']=$row['userName'];
        	$jsonArray->rows[$i]['fullName']=$row['fullName'];
        	$jsonArray->rows[$i]['accessCode']=$row['accessCode'];
        	$jsonArray->rows[$i]['email']=$row['email'];
        	$jsonArray->rows[$i]['addedBy']=$row['addedBy'];
        	$jsonArray->rows[$i]['addedDate']=$row['addedDate'];
        	$jsonArray->rows[$i]['modifiedBy']=$row['modifiedBy'];
        	$jsonArray->rows[$i]['modifiedDate']=$row['modifiedDate'];
        	$i++; 
        } 
         
        echo json_encode($jsonArray);

        The above code will create the following style JSON output.

        {"page":1,"total":1,"records":"3","rows":[
        {"id":"1","userName":"demo","fullName":"Demo User","accessCode":"","email":"demo@myexample.com","addedBy":"1","addedDate":"2009-05-02 00:00:00","modifiedBy":"10","modifiedDate":"2009-06-04 00:00:00"},
        {"id":"2","userName":"sam","fullName":"Sam Lasagne","accessCode":"","email":"sam@myexample.com","addedBy":"2","addedDate":"2009-05-02 00:00:00","modifiedBy":"2","modifiedDate":"2009-08-02 00:00:00"},
        {"id":"10","userName":"adrian","fullName":"Adrian Spaghetti","accessCode":"","email":"adrian@myexample.com","addedBy":"1","addedDate":"2009-05-02 00:00:00","modifiedBy":"2","modifiedDate":"2009-09-01 00:00:00"}
        ]}
        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Using XML in your jQuery to populate input boxes

        2009 - 08.11

        In a previous post I wrote about creating XML pages with MySQL data, using PHP. In this article, I’ll explain in simple terms how to parse that XML data and insert some of its values in to your page using jQuery.

        I’m going to keep this very simple, as there seem to be very few examples of this on the net. It took me a while to work out a neat way of doing this, and I’m sure someone can improve on things. If so – please let me know in the comments.

        First, lets set up an example. A very simple example.

        Imagine an invoice. 4 boxes at the top of a grid, with a ‘Save’ button that will add the contents of those boxes to the list below. The fields are such as ‘Item code’, ‘Description’, ‘Quantity’ and ‘Unit Price’. The user enters the values and clicks the ‘Save’ button to add that row to the list and clear the boxes, ready for the next row to be added. For the purposes of what we are doing, we will also want a 5th box (which would usually be hidden) to store the ‘Invoice Detail Id’.

        Something like this:

        Code Description Quantity Price Hidden ID

        Creating this application is all quite trivial for someone experienced in PHP. However, what would be nice is to be able to edit each row without having to re-load the page. Well we can do this quickly and easily using jQuery.

        Before we start with the jQuery code, we need to have ready a PHP page that will return valid XML with the details of an invoice detail record. Please see my previous post for some help on how to do this.

        This is an example output from the getDetailRow.php file.

        <?xml version="1.0" encoding="utf-8" ?>
        <invoice>
          <invoiceDetail>
            <invoiceDetailId>10</invoiceDetailId>
            <code>CR282</code>
            <description>Software Support</description>
            <quantity>3</quantity>
            <unitPrice>40</unitPrice>
         </invoiceDetail>
        <invoice>

        Against each row, add a button labeled ‘Edit’, and attach some jQuery code that calls a function called editDetailRow(detailRowId) – as the grid is built, insert this code in to each button with the parameter of that row’s detail ID.

        Assuming that there is only ever one result in the XML output, you could use the following code to insert the values in to your input boxes.

        <script type="text/javascript">
        function editDetailRow(detailId) {
            //first we need to load the XML data for that detail row
            //if the function is a success it will call the function called processDetail
            $.ajax({
               type: "GET",
               url: "getDetailRow.php?detailId=" + detailId,
               dataType: "xml",
               success: processDetail
             });
        }
         
        function processDetail(xml) {
            //this function gets the results from the xml file
            //and inserts them in to the boxes
            $(xml).find("invoiceDetail").each(function()   {
                $("#code").val($(this).find("code").text());
                $("#description").val($(this).find("description").text());
                $("#quantity").val($(this).find("quantity").text());
                $("#unitPrice").val($(this).find("unitPrice").text());
                $("#invoiceDetailId").val($(this).find("invoiceDetailId").text());
            });
        }
        </script>

        Yes, it really is that simple. You will need to add a reset button, and make sure you check for a value in the invoiceDetailId when you save (to either call an UPDATE or an INSERT) but thats it.

        Hopefully you will find this useful and can use this as the basis for much more complicated XML and jQuery hookup’s.

        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon

        Creating XML in PHP

        2009 - 07.28

        Quite often I need to create some XML via PHP, pulling data from a MySQL database.

        I have tried various methods but I always come back to this. I like the way that I get full control over doing it explicitly, so thought I would share the code. I am using the MySQL PHP class from Ricocheting.

        There are loads of examples out there already on the web, but I hope the code below is very easy to understand as it uses simple PHP code.

        <?php
         
        //pick up required variables
        $userName = $_GET['username'];
        $password = $_GET['password'];
         
        //include the required files
        require_once('config.php');
        require_once("Database.class.php");
         
        // create the $db ojbect
        $db = new Database($config['server'], 
        	$config['user'], 
        	$config['pass'], 
        	$config['database'], 
        	$config['tablePrefix']);
         
        // connect to the server
        $db->connect();
         
        //build the query
        $query = "SELECT * FROM ".$db->pre."useraccount "; 
         
        //build the where statements
        $where = "WHERE (userAccountId > 0)";
         
        if ($userName) {
        	$where = " AND (userName = '" . $db->escape($userName). "')";
        }
         
        if ($password) {
        	$where = " AND (password = '" . $db->escape($password). "')";
        }
         
        //get the FULL record count
        $sql2 = "SELECT count(0) AS theCount FROM ".$db->pre."useraccount $where";
         
        $countRecRows = $db->query($sql2);
        while ($countRecRow = $db->fetch_array($countRecRows)) {
        	$recordCount = $countRecRow['theCount'];
        }
         
        //execute the main query
        $countRows = $db->query($query . $where);
         
        //set up the php headers so that the page doesnt cache etc
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
        header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
        header("Cache-Control: no-cache, must-revalidate" );
        header("Pragma: no-cache" );
        header("Content-type: text/xml");
         
        //include the page header info
        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
         
        //begin the xml data
        echo "<useraccounts>\n";
         
        //set up the result info
        echo  "<total>$recordCount</total>\n";
         
        //loop through all the records
        while ($row = $db->fetch_array($countRows)) { 
        	echo "<useraccount id=\"".$row['userAccountId'] ."\">\n";
         
        	echo "<username>";
        	echo $row['userName'];
        	echo "</username>\n";
         
        	echo "<fullname>";
        	echo $row['fullName'];
        	echo "</fullname>\n";
         
        	echo "<accesscode><![CDATA[";
        	echo $row['accessCode'];
        	echo "]]></accesscode>\n";
         
        	echo "</useraccount>\n";
        }
         
        echo "</useraccounts>";
         
        //free the result
        $db->close();
        ?>
        • Print
        • Digg
        • del.icio.us
        • Facebook
        • Google Bookmarks
        • LinkedIn
        • MySpace
        • Twitter
        • RSS
        • StumbleUpon