Announcing Sun MySQL!

January 16, 2008 | Leave a Comment

Sun has officially acquired MySQL! As a huge fan and supporter of MySQL, I have personal commitment and obvious concerns about this. In my experience most things Sun does are bloated and slow to develop (Solaris, Java, Open Office). Yet, I remain hopeful because they do seem to respect and work positively with open source initiatives.

The most positive things can come out of this are improved marketing, better name recognition, and funds injected into a project. Maybe they can compete with Oracle now? Hey, maybe Sun will stop using Berkeley DB to back most it’s existing products. I’ll admit that upon first reading this my heart skipped a few beats, but as the pains subsided I think its all going to be OK.

Tags: , , , , , , , ,

Related:

ADOdb - PHP Database Abstraction

August 27, 2005 | 1 Comment

Anyone who has used more than one database (MySQL, PostgreSQL, SQL Server, Oracle, etc) with PHP realizes it is cumbersome. In fact the developers of PHP have recently realized this as well. In 5.1 they are planning to include PHP Data Objects (PDO). However, in the meantime I recommend ADOdb.

Unfortunately, PHP's database access functions are not standardised. Every database extension uses a different and incompatibile API. This creates a need for a database class library to hide the differences between the different databases (encapsulate the differences) so we can easily switch databases.

Example connection to mySQL:

PHP:
  1. $db = NewADOConnection('mysql'); // type of connection
  2. $db->SetFetchMode(ADODB_FETCH_ASSOC); // sets the query results to come back as assoc arrays
  3. $db->PConnect('mysql_db_host', 'some_user', 'some_pass', 'the_db'); // make the connection

Example connection to Oracle:

PHP:
  1. <?php
  2. $db = NewADOConnection('oci8'); // type of connection
  3. $db->SetFetchMode(ADODB_FETCH_ASSOC); // sets the query results to come back as assoc arrays
  4. $db->PConnect('oracle_db_host', 'jpseudo', 'his_password', 'oracle_sid'); // make the connection
  5. ?>

Comparing the two examples it's clear how similar connecting to either database becomes. Also notice we're setting the fetch mode to associative so we get back friendly associative arrays. The following is an example of how to query and get back results:

PHP:
  1. <?php
  2. $query = "SELECT * FROM tablename";
  3. $res = $db->Execute($query);
  4. while($row = $res->FetchRow())
  5. {
  6.      // $row is an associative array, indexed by fieldname from the table
  7.      print_r($row);
  8. }
  9. ?>

This will get back a bunch of rows of data, You might want less, like a single row or single field of a single row.

PHP:
  1. <?php
  2. $row = $db->GetRow("SELECT * FROM tablename WHERE id_field='single_value'"); // this returns an associative array of the single row
  3. $a_field = $db->GetRow("SELECT a_field FROM tablename WHERE id_field='single_value'"); // this returns the value of single field of the single row
  4. ?>

More Resources:

ADOdb Database Abstraction Library for PHP Main Site
ADOdb Documentation
Alternate Abstraction Library: PEAR DB

adodb, database, database abstraction, databases, mysql, oracle, pdo, php, programming

Tags: , , , , , , , ,

Related:

Installing mytop

July 15, 2005 | 3 Comments

Mysql 100X52-64Anyone who's done much MySQL administration probably knows about mytop. mytop is basically a top clone for MySQL. Hugely useful if you want info about what your database is up to, but don't necessarily have pr want MySQL Administrator installed.

I decided to install this on my FreeBSD box, though I'm sure the instructions would be similar on OSX, Solaris, or any other unix flavor. Sometimes the installation can be cumbersome and everytime I do it I find myself fumbling around trying to remember what I did last time. Unfortunately my systems administration skills aren't always as solid as I like. So here goes.

1) Get mytop
2) unpack it in some directory (tar xvf mytop-1.4.tar.gz)
3) add in the necessary perl modules (assuming you don't already have them)
perl -MCPAN -e shell
then at the cpan prompt:
install DBI
install DBD::mysql (this one may fail if your root password for localhost is set. in this case do `force install DBD::mysql`)
install Term::ReadKey
install Term::ANSIColor
install Time::HiRes
4) In the directory where you extracted mytop execute:
perl Makefile.PL
make
make test
make install
5) You can then execute it like:
./mytop -u<user> -prompt -h<hostname>

6) For additional options see: perldoc mytop. Also try hitting '?' when running mytop for runtime options.

cpan, database, database administration, freebsd, install instructions, mysql, osx, perl, perl cpan, solaris, sql, systems administration, unix

Tags: , , , , , , , , , , , ,

Related: