Monthly Archives: September 2010

Magento, Re-init config values of admin module

Assuming that you want to re initialize the configuration values of a module, the fastest way is to manually remove entries from  table “core_config_data

here i want to remove all saved values for module “price” (be careful if there are other modules that uses the same name) :

delete from core_config_data where path like "price/%";

PHP and SQLite, What you need to know.

If you are a MySQL user,  you have certainly acquired mechanism such as string escaping, database connection function are not the same with SQLITE, here a list of important things to know :

SQLite Version 2 and 3

– This is what we can read on the SQLite official site :

The format used by SQLite database files has been completely revised. The old version 2.1 format and the new 3.0 format are incompatible with one another. Version 2.8 of SQLite will not read a version 3.0 database files and version 3.0 of SQLite will not read a version 2.8 database file.

So if you be careful on your choice of which version you’ll use, or you convert SQLite version 2 to version 3 using shell command :

sqlite OLD.DB .dump | sqlite3 NEW.DB

Another important thing to know is that “SQLiteDatabase” will not work with SQLite Version2 you will have an error saying that database is not found or encrypted and to prevent that use PDO instead.

PDO And SQLite

Here some examples of establishing database connection and simple queries :

# SQLite Database init PDO
$sth = new PDO('path/to/my/db.sqlite');

# Insert

# Close connection
$sth = null;

Escaping Strings

Common used function with MySQL is PHP addslashes to escape quotes (simple and double) this will not work with SQLite because escaping is not the same.

To escape quotes (‘) you have to double em (same thing for double quotes), if you want to insert “l’homme” string you have to do like this :

insert into .. values ('l''homme', ..)

But the same advise here, use PDO :

$sting = $sbh->quote($sting_to_quote);

SQLite Tools

SQLite Manager Firefox Extension

Manage any SQLite database on your computer.
An intuitive heirarchical tree showing database objects.
Helpful dialogs to manage tables, indexes, views and triggers.
You can browse and search the tables, as well as add, edit, delete and duplicate the records.
Facility to execute any sql query.

Navicat for SQLite

Navicat for SQLite is a powerful Database administration and development tool for SQLite. It works with SQLite version 2 and 3 and supports most of the SQLite features including Trigger, Index, View, and so on. Features in Navicat are sophisticated enough to provide professional developers for all their specific needs, yet easy to learn for users who are new to SQLite.

WSOD, White screen of death how to deal with it

Sometimes it happens that website  turns into a “beautiful” white page and nothing in the source code of the HTML generated code can help to find why.

This article is meant to help developers to find the common reasons.

“Invisible” Errors :

If error reporting is turned off fatal errors are not showed up (on production environment for example) and this can be the origin of white page. So it’s important to enable it on developement / testing environments, and you can do this by :

Enabling error reporting :

  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);

Using .htaccess file :

  # PHP error handling for development servers
  php_flag display_startup_errors on
  php_flag display_errors on
  php_flag html_errors on
  php_flag log_errors on

Here you can find a nice article about .htaccess directives to handle errors.

Apache logs :

Also another way to track errors is to look on apache logs. The location of these files depends on what you have configured / apache version / vhosts configs .. etc.

To find apache errors logs phpinfo() can be helpfull, look for variable called : error_log

Or by default (on linux) apache logs are on /var/log/apache2/ directory.

To find errors :

  grep -r 'ErrorLog' /var/log/apache2/*

Whitespace at the end of PHP scripts :

This is the common error code that gives WSOD, so one of the best PHP coding practices is to avoid closing php tag (?>) at the end of script.

Infinite loops :

Infinite loops can cause WSOD, but apache can detect this on it will report it on error logs with something like  this :

[notice] child pid ##### exit signal Illegal instruction (4)

To sum up it’s important to know where to search, so first of all error reporting must be active to help to find the origin of the problem. On production environments debug can be tricky so you need to have apache logs accessible.

Extjs, Add tooltip to grid row

The purpose of this tutorial is how to add tooltips for row grids, you can you this when the row is a text field for example.

first of all we need to tell Extjs that row need to be rendered by a custom function, on the column Model add renderer attribute :


{
  id : 'motivation',
  header : 'motivation',
  width: 200,
  dataIndex : 'motivation',
  renderer:addTooltip,

then add the addTooltip function :


function addTooltip(value, metadata, record, rowIndex, colIndex, store){
    metadata.attr = 'ext:qtip="' + value + '"';
    return value;
}

Mac Os, Web developer tools

Being a Mac user since 4 years this is my selection of softwares that i’m using every day on my job as a web developer :

Zend Studio for eclipse

The best IDE (for me) to develop web applications with Xdebug integration, simple template insertion,project library parsing and many other stuffs, however Netbeans could be an alternative but it’s still having memory allocations problems (see Netbeans Forum).

Sequel Pro (free)

MySQL database management for MacOS, simply the best!

Navicat-lite (free)

Navicat Lite is a multi-connections Database Administration tool allowing you to connect to MySQL, PostgreSQL and Oracle databases simultaneously within a single application

Mamp (free)

Manage websites locally, no apache & MySQL installation, it’s ready to use. With Pro version (Mamp Pro) it’s possible de manage virtual hosts, dynamic Dns etc.

CyberDuck (free)

FTP, SFTP, WebDAV, Cloud Files, Google Docs & S3 Browser for Mac & Windows.

Terminal

Access Unix basis of Mac Os, useful for creating / searching content, files, SSH, FTP commands etc.

Firefox (free) with firebug extension

The Best browser for web developing / javascript debug.

Soap Client (free)

SOAP Client is a free Cocoa-based developer tool for Mac OS X Tiger that allows you access and debug WSDL & SOAP-based Web Services from the comfort of your desktop.

MySQL Workbench (free)

MySQL Workbench is a cross-platform, visual database design tool developed by MySQL. It is the highly anticipated successor application of the DBDesigner4 project. MySQL Workbench is available as a native GUI tool on Windows, Linux and OS X in different editions. See the following link for more information about the editions available.