Last few days we are transfering our code from prototype to jQuery. I found jQuery
to be better than prototype, better documentation, plugins, and much easier.
I had a problem with date fields, that needed to be in format dd.mm.yyyy.
By default jQuery validation plugin works with dates yyyy/mm/dd.
To resolve this issue, and make it work with your format :
$.validator.addMethod(
"customDate",
function(value, element) {
return value.match(/^\d\d?\.\d\d?\.\d\d\d\d$/);
},
"Date error, format dd.mm.yyyy"
);
Later in you HTML code in date field put this :
Wednesday, August 19, 2009
Speed up your PHP application
Hi to all!!
Today I will be talking about handling errors trough our localhost and speeding our application.
Typical error handling when you by default install Apache/PHP is nothing special,
bunch of ugly error messages displayed on your screen :)
Second and the most important thing is speeding up your code, finding all those bottlenecks in your application,
and belive me, you will have them. Especially if you are developing huge application or framework and after a while you
decide to check your coding :)
Now, let's get to work!
First we need to install :
- Xdebug : Wondreful thing for handling errors from PHP. You will definetly love it.
Go to http://www.xdebug.org/ and download it. All you need is to put .dll (Sorry to all that are working on
Linux), but on xdebug site you have all documentation for installing this is just a quick tour (windows) :)
Include your .dll in php.ini and restart apache.
Now let's talk about error handling in general, configuring it to work as we need and when we need error display.
First open your php.ini :
display_errors = On
error_reporting = E_ALL
With this two lines you set up PHP to display every kind of error there is. Now the real question to this, do we realy need
all theese errors. Answer: you will need them occasionally, when you are testing code and application.
Shure you will need to see all those notices, this is very important because this way you will see everything.
First step to speeding application is removing errors :)
But definetly you will need them occasionally, so in your index.php or configuration.php (script that you allways call) set up
this line :
display_errors(0);
Now, every time you need errors you set this to 1, and with xdebug you will have beautifull messages instead of those ugly ones
that you had before.
One thing before we proceed, in php.ini you have to add this line of code
[XDEBUG]
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "d:\webs\errors"
Change output dir into whatever dir you want, this is the place where xdebug will output his report.
Now one last thing to download :
WinCacheGring
WinCacheGrind is tool that reads xdebug output and displays information about execution of our code.
Now if you open it you can analyze in details every segment of your code, and with function that has been executed
you can see timing (how long does it takes to execute). I don't need to tell you how important is this, how this
will help speed up your coding and realy give you guidance what are you doing wrong or right :)
Cheers!
Today I will be talking about handling errors trough our localhost and speeding our application.
Typical error handling when you by default install Apache/PHP is nothing special,
bunch of ugly error messages displayed on your screen :)
Second and the most important thing is speeding up your code, finding all those bottlenecks in your application,
and belive me, you will have them. Especially if you are developing huge application or framework and after a while you
decide to check your coding :)
Now, let's get to work!
First we need to install :
- Xdebug : Wondreful thing for handling errors from PHP. You will definetly love it.
Go to http://www.xdebug.org/ and download it. All you need is to put .dll (Sorry to all that are working on
Linux), but on xdebug site you have all documentation for installing this is just a quick tour (windows) :)
Include your .dll in php.ini and restart apache.
Now let's talk about error handling in general, configuring it to work as we need and when we need error display.
First open your php.ini :
display_errors = On
error_reporting = E_ALL
With this two lines you set up PHP to display every kind of error there is. Now the real question to this, do we realy need
all theese errors. Answer: you will need them occasionally, when you are testing code and application.
Shure you will need to see all those notices, this is very important because this way you will see everything.
First step to speeding application is removing errors :)
But definetly you will need them occasionally, so in your index.php or configuration.php (script that you allways call) set up
this line :
display_errors(0);
Now, every time you need errors you set this to 1, and with xdebug you will have beautifull messages instead of those ugly ones
that you had before.
One thing before we proceed, in php.ini you have to add this line of code
[XDEBUG]
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "d:\webs\errors"
Change output dir into whatever dir you want, this is the place where xdebug will output his report.
Now one last thing to download :
WinCacheGring
WinCacheGrind is tool that reads xdebug output and displays information about execution of our code.
Now if you open it you can analyze in details every segment of your code, and with function that has been executed
you can see timing (how long does it takes to execute). I don't need to tell you how important is this, how this
will help speed up your coding and realy give you guidance what are you doing wrong or right :)
Cheers!
Monday, August 17, 2009
PostgreSQL AUTOINCREMENT field
Past few days i have been working on developing database for sport statistics.
Client demanded that we develop it on PostgreSQL.
I am kind of a mysql geek and I am used to work with auto increment fields, and PostgreSQL doesn't have
tipical autoincrement fields like MySQL has.
And all that was needed was this :
ALTER TABLE ourtable ADD ourid INT unsigned NOT NULL AUTO_INCREMENT_UNIQUE;
So we needed to find solution for this.
This is the procedure for creating "auto-increment" field in PostgreSQL.
First we have a table (lets name it ourtable), and we need to create cequence :
CREATE SEQUENCE ourtable_seq;
After creating cequence we are adding field to our table :
ALTER TABLE ourtable ADD ourid INT UNIQUE;
ALTER TABLE ourtable ALTER COLUMN ourid SET DEFAULT NEXTVAL('ourtable_seq');
And that's it. Everything that you insert after this last alter will have autoincrement on row ourid.
If for example you already have fields, that you previously inserted they don't have anything in ourid row, we need to
populate this :
UPDATE ourtable SET ourid = NEXTVAL('ourtable_seq');
That's it.
Next article will be how to speed up your application :)
Client demanded that we develop it on PostgreSQL.
I am kind of a mysql geek and I am used to work with auto increment fields, and PostgreSQL doesn't have
tipical autoincrement fields like MySQL has.
And all that was needed was this :
ALTER TABLE ourtable ADD ourid INT unsigned NOT NULL AUTO_INCREMENT_UNIQUE;
So we needed to find solution for this.
This is the procedure for creating "auto-increment" field in PostgreSQL.
First we have a table (lets name it ourtable), and we need to create cequence :
CREATE SEQUENCE ourtable_seq;
After creating cequence we are adding field to our table :
ALTER TABLE ourtable ADD ourid INT UNIQUE;
ALTER TABLE ourtable ALTER COLUMN ourid SET DEFAULT NEXTVAL('ourtable_seq');
And that's it. Everything that you insert after this last alter will have autoincrement on row ourid.
If for example you already have fields, that you previously inserted they don't have anything in ourid row, we need to
populate this :
UPDATE ourtable SET ourid = NEXTVAL('ourtable_seq');
That's it.
Next article will be how to speed up your application :)
Here we go, post no. 1
Hi to everyone!
This is my first post here, so for now I am try'n to adopt here. This blogging is kind of a new thing to me. I have been developing this things but never realy worked on it so be gentle to me :)
I promise that new post will be here during this day.
See you again later :)
This is my first post here, so for now I am try'n to adopt here. This blogging is kind of a new thing to me. I have been developing this things but never realy worked on it so be gentle to me :)
I promise that new post will be here during this day.
See you again later :)
Subscribe to:
Posts (Atom)