2009-10-17

Kohana XML helper module

Important! All Kohana-related posts are now at http://kohana.lillem4n.se.

This module is actually just a helper (for now, at least). But it is very handy when working with converting various data to XML in PHP. A few examples:

Simple example of the two different return values.
As DOMDocument:
<?php
$doc = xml::toXML(array('root'=>array('fnupp'=>'dah')));
$doc->formatOutput = true;

echo $doc->saveXML();
?>


As DOMNode:
<?php
$doc = new DOMDocument();
$container = $doc->appendChild($doc->createElement('root'));

xml::toXML(array('fnupp'=>'dah'), $container);

echo $doc->saveXML();
?>


How the $container works:
xml::toXML(array('fnupp' => 'dah'))

will output:
<fnupp>dah</fnupp>

xml::toXML(array('fnupp' => 'dah'), 'root')

will output:
<root>
<fnupp>dah</fnupp>
</root>

That was just a few examples, full documentation is within the helper PHP-file. That includes passing SQL and getting it back as XML directly, working with attributes etc.

All feedback is very welcome!

Hashes: #kohana xml module #kohana module #kohana #xml #php

2009-10-12

postgreSQL crash course

As I was searching for a INNER JOIN problem in postgreSQL, I ran across this must awsome guide. With examples and all. Easy to overview. Starting from a very basic level, increasing to very in depth knowledge of postgres inner workings.

http://www.commandprompt.com/ppbook/x5802

Hashes: #postgreSQL #database #postgre #SQL

Port Forwarding in Ubuntu with iptables

Assuming your ubuntu box already have NAT up and running, and you wish to connect directly to the internet from a machine behind your Router (Ubuntu, GNU/Linux-box).

iptables -A PREROUTING -t nat -i ##incomming interface## -p tcp --dport ##incomming port## -j DNAT --to ##destination IP##:##destination port##

For example:
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 8080 -j DNAT --to 10.1.249.250:80

When I wanted to access a web server behind my Ubuntu NAT-router in my home. Now I can surf to #mydomain#:8080 to access that internal web server at port 80.

Hashes: #linux #ubuntu #nat #port forwarding #iptables