Stay hungry, Stay foolish

What is PHP Composer?

It’s a very good dependency management tool for PHP. It manages all the libraries that you have on your project.

Advantage

The composer will pull all the required libraries, dependencies and keep track all of them just in individual project not globally. Furthermore, you might be aware of PEAR which is established as PHP package manager. However, it has been abandoned for several reasons. First of all, much of the code in PEAR is out of date. Secondly, PEAR forces you to install packages system wide rather than on a project-by-project.

Installation

Installing composer is quite easy. In this tutorial, I’ll use curl to install composer thus make sure you have curl installed or enabled in your system. If not, use the following to install

Usage

Now that you have composer installed. To use the composer, it requires composer.json file in which describes the dependencies of your project. For instance, our project depends on PEAR, Mail, Mail_Mime, Net_SMTP, Service_JSON. So let’s create the file:

One question rising from here is that where you can find the package and the version for this file. Here is a good place for you to do that.
Ok now you can run a command to install those dependencies on your project:

php composer.phar install

Autoloading

Once you have all your dependencies installed. You need to autoload them into your project. In your PHP project, simply specify this in your index or bootstrap file:

require 'vendor/autoload.php';

Conclusion

Composer is now widely used by many PHP developers. So it’s better for you to start using it today.

There’s a problem with above UPDATE statement. In the subquery “SELECT VALUE1, VALUE2 FROM TABLE_NAME2 AS T2 WHERE T1.COL1=T2.COL2”, if it returns NULL values, your query could update with those NULL values. Hence, you should have a WHERE condition to prevent this problem, for example:

Rate this:

Using jQuery cookies to maintain user states becomes more popular. However, i’ve recently found a problem where state didn’t appear to be persisting and on viewing the cookie information, using the web developer toolbar, i had multiple versions of the same cookie.

when a cookie is created, its path is set default to ‘/’ meaning that the cookie is valid throughout the whole domain

Cookies can also be set per directory and they’ll be valid for a certain set of pages.

Therefore, to overcome this problem, instead of a simple name, value pair: