Store native XML in a DB2 table
IBM DB2 is the first RDBMS to provide a native XML facility, in a table. You will be able to insert in a column, some XML data. It will be easier to make direct requests to these data with XQuery.
So, it’s funny, but why it’s interesting to do that ? Because XML data are hierarchic (instead of relational data which are flat) and data self-describing through XML tags. XML also allows a better flexibility for data structures required to change very often. In the other hand, access time performances will be a little slower, we lose the integrity constraints, and OLAP queries will be more difficult. The important question is “Which flexibility-performance ratio do you need ?”.
Let’s start now with the creation of a database, which should be encoded with UTF-8, to store XML. For that, we use the CREATE DATABASE command:
CREATE DATABASE xmldb USING CODESET UTF-8 TERRITORY US
We have our table, now we should create the “client” table, with an “info” column who contain client information, in XML format:
CONNECT TO xmldb CREATE TABLE client (id INT, info XML)
Let’s try to insert a new client with a SQL query:
INSERT INTO client (id, info) VALUES (1, '<clientinfo xmlns="http://posample.org" Cid="1"><name>Sophie Bool</name><addr country="France"><street>5 rue du chateau de stable</street><city>Paris</city></addr><phone type="work">01 72 92 02 88</phone></clientinfo>')
The first thing you will told me is this query is a normal SQL query, and this is right, insert XML isn’t more difficult. The second thing is about the XML, here we have a short XML data, but if we have more, it will be very difficult to use. This why, we will use XQuery to manipulate these data or use a XDS import. I’ll come back soon on these points.
Use Renren chat with Adium for Mac OS X
As we did for QQ with Adium, we can connect to Renren (Xiaonei) chat with Mac OS X. This time it will be very easy, just need to fill an account with the right informations:
First we need to create a Jabber Account on Adium, we will use a special “ID”, which is your ID on Renren. If you don’t know your ID, just go to you profile page (个人主页), and look at the address bar, for me it’s like:
Just not the number after the “id=“. My Jabber ID (用戶名) will be “250388793@renren.com” and the password (密碼) will be the same as my Renren password.
Now let go to the Options pane (帳戶選項), to modify the connect server (服務器) option to “talk.renren.com” and verify that the port (端口) is “5222“. Then .. it’s finish, confirm and connect ! You’ll see all your friends, organized by groups :)
WordPress 3.0 is now available
After thirteen major release of WordPress and half year of work by 218 contributors, WordPress 3.0 is now available for download.
This new release come with a new default theme called Twenty Ten, which is coming with new APIs allowing easy modification of the background, headers, shortlinks, menus, post types,.. MU and WordPress as been merged to make it possible to run one blog or ten million from the same installation. And also a new lighter interface, contextual help, more than 1,200 bug fixes and feature enhancements. For more information just go to the Codex WP 3.0 or just watch the video:
P1.cn is launching is P1 Mall
The private social network P1, sharing international lifestyle, common values and interests just opened it “P1 Mall”. This mall providing exclusive items and special offers is only available to P1 members.. who only can only be obtained through invitation.
P1 Mall providing goods of iconic luxury brands at prices up to 90% off retail. You can start now, and go to the P1 Mall.
DB2 queries with PHP
You want to use PHP as programmation language to query your DB2 databases. We will see how to do. We only need a HTTP server with the PECL ibm_db2 extension. This extension allow us to use new functions, relative to IBM DB2, but also work with IBM Cloudscape and Apache Derby.
After the installation, we will use these functions as normal PHP functions. This is a connection example to the SAMPLE database. You can click on the function to get more information:
<?php $conn = db2_connect('SAMPLE', 'db2user', 'secretpass'); if($conn) { echo "connection to sample: ok."; } else { echo "connection to sample: failed."; } db2_close($conn); ?>
Nothing very complicated here, we connect to the SAMPLE database with the db2_connect function, and we check if the connection works, then we close the connection with db2_close.
Now, let’s do something more interesting, do some query on our tables !
<?php $query = "SELECT * FROM ADMINISTRATOR.EMPLOYEE"; $stmt = db2_prepare($conn, $query); if($stmt) { $ex = db2_execute($stmt); if($ex) { while($ligne = db2_fetch_array($stmt)) { $lastname = ligne[3]; echo "<br />- $lastname"; } } } ?>
We put your query in the $query variable, and we use the db2_prepare function with the previous connection ($conn). This function will “prepare” (I’m so smart), it will create an optimized path in DB2, to be more fast. We execute this result ($stmt) with the db2_execute function, who do the query on your database. To finish, we use db2_fetch_array to retrieve our data in an array.
A BLOB example.. or Binary Large OBject, an image, a audio or video file,..
$filename = '/home/mycado/itsme.jpg'; $name = 'My cute picture"; $query = 'INSERT INTO photo (id, name, image) VALUES (?, ?, ?)'; $stmt = db2_prepare($conn, $query); if($stmt) { db2_bind_param($stmt, 1, 'id', DB2_PARAM_IN); db2_bind_param($stmt, 2, 'name', DB2_PARAM_IN); db2_bind_param($stmt, 3, 'filename', DB2_PARAM_FILE); $ex = db2_execute($stmt); }
We use the flag db2_bind_param we give us more precision with the data type in our request. The first two variables, an id and a string, use DB2_PARAM_IN, an classical input parameter et we put your picture with DB2_PARAM_FILE. Note that the question marks are not an error !
It’s enough for now, I advice you to read the ebook “DB2 Express-C: The Developer Handbook for XML, PHP, C/C++, Java, and .NET‘. About the ibm_db2 functions, you can find them all on php.net.

