Wednesday, September 10, 2008

When to use PHP?

PHP is Scripting Language and can be used when:
Creating Web pages that contain dynamic contents.
Responding to HTML forms.
Accessing databases.
Securing data.

Compare PHP and Cold Fusion.

PHP is commonly said to be faster and more efficient for complex programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion’s strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially requires more programming knowledge. Cold Fusion is designed with non-programmers in mind, while PHP is focused on programmers.

Compare PHP and PERL.

The biggest advantage of PHP over P E R L is that PHP was designed for scripting for the web where P E R L was designed to do a lot more and can because of this get very complicated. The flexibility / complexity of P E R L makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format without losing flexibility. PHP is easier to integrate into existing HTML than P E R L. PHP has pretty much all the ‘good’ functionality of P E R L: constructs, syntax and so on, without making it as complicated as P E R L can be. P E R L is a very tried and true language, it’s been around since the late eighties, but PHP is maturing very quickly.

What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars only takes care of <, >, single quote, double quote and ampersand whereas htmlentities translates all occurrences of character sequences that have some other meaning in HTML.

Difference between mysql_connect() and mysql_pconnect()

mysql_connect() and mysql_pconnect() both are working for database connection but with little difference. In mysql_pconnect(), ‘p’ stands for persistance connection.

When we are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request .

But in case of mysql_pconnect() function,
First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the connection will remain open for future use (mysql_close() will not close connection established by mysql_pconnect()).

mysql_pconncet() is useful when you have a lot of traffice on your site. At that time for every request it will not open a connection but will take it from the pool. This will increase the efficiency of your site. But for general use mysql_connect() is best.

I think this is a very imp concept in case of Database Connectivity.