Pedro's blog: db2, mysql, php, linux and performance


fix for the respo wordpress theme

Respo wordpress theme screenshotThe Respo wordpress theme is a cool theme for wordpress. It is free and it has a clean and simple design. After installing it you will find that the pictures of the posts in the blog ‘loop page’ are not working. To fix it I was researching a little in google and I found out a way to make it work for me:

  1. Update the file wp-content/themes/respo/js/timthumb.php with the last version of the timthumb.php in the repository.
  2. Comment the line 825:

    // $docRoot = @$_SERVER[‘DOCUMENT_ROOT’];

  3. Check that every post has assigned is Featured Image.

After doing the 3 steps, the pictures are working in the blog ‘loop’s page’ and the problem with the respo timthumb.php script is fix!



SQL16061N The value cannot be constructed as, or cast (using an implicit or explicit cast) to the data type SQLSTATE=10608
28/05/2011, 13:30
Filed under: DB2,PHP,xQuery | Tags: , , , , ,

Everything was working properly until one of the users add a summary artwork greater than the cast size in the xquery select.
Here the select i am using:

select A.ARCHIVO_ID,
F.ARCHIVO_FORMATO_DESCRIPCION_ES,
X.NOMBRE#,
X.RESUMEN#,
X.AUTOR#
from ARCHIVO A,
ARCHIVO_FORMATO F,
ARCHIVO_LOCALIZACION L,
ARCHIVO_TECNICA T,
ARCHIVO_CATEGORIA C,
ASIGNATURA_ARCHIVO AA,
ARCHIVO_BIBLIOGRAFIA B ,
xmltable(
‘$c/obra’ passing A.ARCHIVO_CARACTERISTICAS as “c” columns
NOMBRE# VARCHAR(100) path ‘nombre’,AUTOR# VARCHAR(100) path ‘autor’,
RESUMEN# VARCHAR(1000) path ‘resumen’
) as X
where A.ARCHIVO_ESTADO BETWEEN 1 AND 2 AND
A.ARCHIVO_PRIVADO = ‘N’ AND

The describe table:

db2 => describe table archivo

Data type Column
Column name schema Data type name Length Scale Nulls
——————————- ——— ——————- ———- —– ——
ARCHIVO_ID SYSIBM INTEGER 4 0 No
ARCHIVO_FORMATO SYSIBM INTEGER 4 0 No
ARCHIVO_TIPOLOGIA SYSIBM INTEGER 4 0 No
ARCHIVO_LOCALIZACION SYSIBM INTEGER 4 0 No
ARCHIVO_ESTADO SYSIBM INTEGER 4 0 No
ARCHIVO_VISITAS SYSIBM INTEGER 4 0 No
ARCHIVO_USUARIO_CREACION SYSIBM INTEGER 4 0 No
ARCHIVO_IP_CREACION SYSIBM VARCHAR 16 0 No
ARCHIVO_FECHA_CREACION SYSIBM TIMESTAMP 10 6 No
ARCHIVO_USUARIO_MODIFICACION SYSIBM INTEGER 4 0 Yes
ARCHIVO_IP_MODIFICACION SYSIBM VARCHAR 15 0 Yes
ARCHIVO_FECHA_MODIFICACION SYSIBM TIMESTAMP 10 6 Yes
ARCHIVO_PRIVADO SYSIBM VARCHAR 1 0 No
ARCHIVO_NOTA SYSIBM DOUBLE 8 0 Yes
ARCHIVO_CARACTERISTICAS SYSIBM XML 0 0 No
ARCHIVO_SOURCE SYSIBM BLOB 262144000 0 Yes

A XML file example:

<?xml version=”1.0″ encoding=”iso-8859-15″?>
<obra tipo=”Imagen”>
<nombre>Sin t&amp;iacute;tulo</nombre>
<autor>Vicente Ort&amp;iacute; Mateu</autor>
<periodo>Siglo XXI</periodo>
<archivo>42.jpg</archivo>
<resumen>escultura en m&amp;amp;aacute;rmol crema Valencia y madera, colecci&amp;amp;oacute;n particular</resumen>
<mime_type></mime_type>
<alto>2352</alto>
<ancho>2208</ancho>
<descriptores>
<descriptor></descriptor>
</descriptores>
</obra>

And here the error:

SQL16061N The value “El presente artículo constituye un inv…” cannot
be constructed as, or cast (using an implicit or explicit cast) to the data
type “VARCHAR_1000”. Error QName=err:FORG0001. SQLSTATE=10608

I had to change the cast from RESUMEN# VARCHAR(1000) to RESUMEN# VARCHAR(2000) because the select was failing and I was getting 0 results…



Function ereg() is deprecated in…
23/05/2011, 20:16
Filed under: Apache,GNU/Linux,PHP

I just update the php of one of the servers I’m handling on and I got a surprise… every f*cking ereg() or eregi() function was displaying a pretty sentence:

Function ereg() is deprecated in…

How to disable this annoying warnings?
Fast solution:go to the php.ini file and add an ~E_DEPRECATED on the error_reporting var like:

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

Best solution:use preg_match() instead

Enjoy!



DB2, Zend, ajax, and the charset codification.
22/05/2010, 11:43
Filed under: DB2,General,PHP | Tags: , , , ,

Hi again, I have to apologize because I’ve been in holidays and I didn’t write so often in last weeks.

On last week I had a problem with the codification in DB2 and the codification of the html layout.

The database is defined with this line:

db2 “CREATE DATABASE D2MU AUTOMATIC STORAGE YES ON ‘/home/db2inst1’ ALIAS D2MU USING CODESET ISO-8859-15 TERRITORY ES”

And the html layout includes this meta tag:

<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-15” />

So, if I disable the layout (with zend):

$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();

The special chars in the text obtained from the database were not show in the proper codification, what I did for fixing it? I included a line in the HTTP headers like:

header (‘Content-type: text/html; charset=ISO-8859-15‘);

And the problem was solved!



DB2, PDO, BLOBs and XML with Zend
21/02/2010, 12:46
Filed under: DB2,PHP | Tags: , , ,

What’s the secret of using PHP with PDO over DB2? there are a lot of secrets! one of them is the use of blobs and xml files. I’m going to show how I made it work.

First of all I’m working with big files, so I need a way of handling big files from the the HTTP request (working with Zend), here it comes:

$upload         = new Zend_File_Transfer_Adapter_Http();

$registry         = Zend_Registry::getInstance(); //Getting the registry with the config values
$config            = $registry->configuration; //Getting the config
$destination     = $config->upload->directory; //Getting the upload directory

$upload->setDestination($destination);
//You can add validators here…
//$upload->addValidator(‘ExcludeMimeType’, false, ‘application’);

if (!$upload->receive()) {
//Do something because there is an error!
}

//Getting the full file name and the file name
$fileName          = $upload->getFileName(‘archivo’);
$filenameshort = $upload->getfileName(‘archivo’, false);

try{

//Opening the file and reading it…
$fileHandle = fopen($fileName, “r”);

if($fileHandle){
$fileContent = fread($fileHandle, filesize($fileName));

if (!is_string($fileContent)) {

//Do something with the error

}
}else {
//Do something with the error
}
//We got an error!
}catch(Exception $e){

//Do something with the error
//And removing the file..
unlink($fileName);
return $this->_redirect(‘main/add’);
}

Now we have the file source in $fileContent and we can play with it. Easy, right?

In the case I want to add some XML files after generating them or from the file system… how can I do it? IBM offers a set of UDF files called “XMLFromFile functions” (you can find them in http://www.ibm.com/developerworks/exchange…) because if the XML tree is getting super big, there are some troubles with the maximum SQL insert sentence size. Better to use this User defined functions:

$datos[‘ARCHIVO_CARACTERISTICAS’]   =

new Zend_Db_Expr(” clobFromFile(‘”.$xmlObject->getFileName().”‘) “);

//The function getFileName returns the full file name of the XML file on the system and the Zend_Db_Expr doesn’t add any extra quotes to the file name.

After we load the binary file in a PHP variable and we know how to get an XML file from the file system, the rest is to add everything to the database:

$datos[‘ARCHIVO_SOURCE’]  = $fileContent;

$datos[‘ARCHIVO_CARACTERISTICAS’]   =

new Zend_Db_Expr(” clobFromFile(‘”.$xmlObject->getFileName().”‘) “);

$tabla = new tablaArchivo();
$tabla->insert($datos);

The database table tablaArchivo looks like:

class tablaArchivo extends Zend_Db_Table_Abstract{
protected $_name     = ‘ARCHIVO’; //Table real name
protected $_primary = ‘ARCHIVO_ID’; //Table primary key
//References to other tables and other stuff here…
}

There you go! an easy way of loading binary files and xml files on DB2 with the help of PHP, PDO, the IBM UDF XMLFromFile functions and Zend.

Sources:

XMLFromFile functions

PDO_IBM

DB2 Express-C



Apache died after updating Ubuntu, pdo_ibm.so and php_pdo_declare_long_constant
06/02/2010, 12:51
Filed under: Apache,DB2,GNU/Linux,PHP | Tags: , , , , ,

After some months I installed my Ubuntu Server, yesterday I decided to update it, so:

$ apt-get update

$ apt-get upgrade

Between all the packages I found out php5, php5-dev, php5-common, php5-cli and libapache2-mod-php5, none of them should be dangerous… or maybe yes. I reboot and… crap, Apache doesn’t work! I tried to restart the daemon and got nothing, didn’t want to work. I took a look to the /var/log/apache2/error.log and I found:

/usr/sbin/apache2: symbol lookup error: /usr/lib/php5/20060613/pdo_ibm.so: undefined symbol: php_pdo_declare_long_constant

Something was wrong with the pdo_ibm module… I reinstalled again:

$ wget http://pecl.php.net/get/PDO_IBM-1.2.5.tgz

$ tar zxvf PDO_IBM-1.2.5.tgz

$ cd PDO_IBM-1.2.5

(Removed the line with the PDO dependency from the package.xml file: <dep type=”pkg” rel=”has” version=”1.0.0″>PDO</dep>)

$ pecl uninstall package.xml

$ pecl install package.xml

I tried again /etc/init.d/apache start and still didn’t work, so I decided to reinstall PDO:

$ pecl uninstall pdo

$ pecl install pdo

And after started apache /etc/init.d/apache start it worked!



ZDE on Snow Leopard makes code disappear!
05/02/2010, 18:22
Filed under: General,macosx,PHP | Tags: , , ,

What a surprise, just moved from MacOSX Leopard to Snow Leopard and what did I find?

Zend Development Studio doesn’t like the Java version already installed, the code is disappearing! the Java I had:

$ java -version
java version “1.6.0_17”
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)

I research a little and I found the fix: OS X 10.6 Snow Leopard Java problems (and fix)

At the end, everything working on 1.5:

$ java -version
java version “1.5.0_19”
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_19-b02-304)
Java HotSpot(TM) Client VM (build 1.5.0_19-137, mixed mode, sharing)

Enjoy it!

http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard



Disable log on htaccess
30/01/2010, 9:45
Filed under: General,PHP,Security | Tags: , ,

How to disable the logging function of a well defined php script with the htaccess file?

SetEnvIf Request_URI “^/yourdir/yourfile\.php$” dontlog