NYCPHP Meetup

NYPHP.org

[nycphp-talk] XAMPP: Upgrading MySQL

John Lacey jlacey at att.net
Sat Jul 24 19:55:34 EDT 2004


Hans Zaunere wrote:

>>anyone here know how hard/easy it is to upgrade the mysql version that
>>is pre-packed with XAMPP?
> 
> 
> Not sure... certainly doable, I'd imagine, but you'd probably be getting
> into the realm of installing a separate MySQL instance on the box and
> disabling that which comes with XAMPP.

I've done exactly this on a number of occasions, but switching to 4.1 
wasn't one of them :)

> 
> 
>>they have version 4.0.20 and i would like to upgrade to 4.1
> 
> 
> Be careful here... there's a major difference between the two.  Chances
> are, your code will break.
> 
> MySQL 4.1.x uses a new binary protocol, and requires the
> http://php.net/mysqli extension to work.  You can set MySQL to be
> backwards compatible, but then you'll miss the benefits of the binary
> protocol (prepared statements, no escaping, etc).
> 
> 
>>also anyone here used the SQLite extension?  Is this better to use
> 

Yeah, what Adam and Hans said...

Here's a few snippets from a program that I added SQLite support to--you 
can compare some of the statements. For example, there is no 
'fetch_object' in SQLite so I had to CAST it to an object before I could 
use it, etc.


// this function only used for escape in uploaded images
function escape_data($data, $size = 0)
{
     switch ($this->db_type) {
         case 'mysql':
             $escaped_data = addslashes($data);
             break;
         case 'sqlite':
             $escaped_data = sqlite_escape_string($data);
             break;
     }
     return $escaped_data;
}


// here's the CAST I mentioned above
function fetch_object($result, $row = '0')
{
     switch ($this->db_type) {
         case 'mysql':
             return mysql_fetch_object($result);
         case 'sqlite':
             if (sqlite_has_more($result)) {
                return (object)sqlite_fetch_array($result, SQLITE_ASSOC);
             } else {
             return FALSE;
             }
     }
}


// and a piece of some error code
function sql_error($query = FALSE)
{
     global $admin_email;

     switch ($this->db_type) {
         case 'mysql':
             $this->sql_error_number = mysql_errno($this->link_id);
             $this->sql_error_name = mysql_error($this->link_id);
             break;
         case 'sqlite':
$this->sql_error_name=sqlite_error_string(sqlite_last_error($this->link_id));
         break;
     }


{Adjusted a few indents to not wrap the code}

John





More information about the talk mailing list