| Subcribe via RSS

SQL tuning teleconference on September 1 from IBM

August 23rd, 2009 | No Comments | Posted in IBM DB2, IBM system z |

A new teleconference from IBM on SQL tuning for DB2 on system z coming on Tuesday, September 1, starting at 3pm (UTC). Aim for application programmers, application development managers, database administrators and database managers,  with an intermediate technical level. With the growing of the IT infrastructure, we must find how can we deliver a scalable, reliable, available and highly secure database infrastructure, in a cost-effective data server environment !

The case study will explain:

  • How the project was started
  • Which techniques and strategy were used
  • How follow-up was done
  • What investments where made
  • What was the return on investment

The speakers are Surekha Parekh, DB2 Market Manager/Strategist, IBM Software Group and Kurt Struyf, Senior Consultant from Competence Partners.

You can register at SQL tuning: the necessity, the benefits, a business case.

Tags: , , ,

DB2 queries with PHP

August 16th, 2009 | No Comments | Posted in IBM DB2, Programming |

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.

Tags: , ,

Start on DB2 with IBM DB2 Express-C

August 15th, 2009 | No Comments | Posted in IBM DB2 |

You should have heard something about IBM DB2, but it’s still two letters and a number for you. We will see how to start with DB2, in the good and free way ! (and.. legal).

IBM DB2 is a relational database management system, using SQL language. Created in 1983 by IBM, and the last version is the 9.7 (Cobra). Compatible with the major operating systems (z/OS, AIX, Unix, Linux, Windows, Mac OS,..), DB2 ranks second in terms of market share, behind Oracle. There are several versions of DB2, more or less specialized and offer more or less services, but we will choose the free version, who can be use by students, developers, or small companies. DB2 Express-C is free to develop, deploy and distribute.

DB2 Express-C only have two limitations, which are not problem for us. It supports only 2 core and up to 2GB of RAM, which is enough for our tests. This version is available for Linux (32bit, 64bit and POWER), Windos (32bit and 64bit), Solaris (Intel 64bit), and Mac OS X (Intel 64bit), but unavailable for z/OS.. still not a problem for us ! There is no other limitation, we are free for the database size, number of connected users,.. Whether you develop in Java, .Net, Ruby, Python, Perl or pretty much any other programming language out there

We will proceed to the crucial stage, downloading DB2 Express-C 9.7 and install it on your system. To go further, don’t hesitate to consult the excellent ebook Getting Started with DB2 Express-Cand watch the videos on channelDB2.

Tags: ,

Check the service level and version of DB2

August 15th, 2009 | No Comments | Posted in IBM DB2 |

A short easy command will allow us to check the version and service level (build level and fix pack) of our DB2 instance. For that, use the db2level command:

DXIIC:/ mycado$ db2level

DB221085I Instance “DB2″ uses “32″ bits and DB2 code release “SQL09052″ with level identifier “03030107″.
Informational tokens are “DB2 v9.5.200.315″, “s080811″, “WR21411″, and Fix Pack “2″.
Product is installed at “C:\DB2v95″ with DB2 Copy Name “DB2COPY1″.

Here I use a DB2 9.5 with the fix pack 2 ! These information can be useful when you search information or when you need a support from IBM, but essentially to know if you have the latest fixpack. The latest fixpack for DB2 9.5 is the fix pack 4.

Tags: , ,