What is the difference between inner join and outer join?
Inner join displays rows from table where the data is available in both the tables, where in outer join we can configure it to bring out rows from one table where the data is missing in other table for the corresponding rows.
Inner join
Say you have one table of CUSTOMERS and one table of ORDERS. Each row in the ORDERS table has a reference (foreign key reference) to a customer id which represents what customer placed that order. If you want to run a query that lists the orders along with the names of the customers who ordered them (since a customer id number itself it pretty useless), you will want to execute a join query:
SELECT CUSTOMERS.NAME, ORDERS.NAME
FROM CUSTOMERS
INNER JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID
Outer join
If for some reason, you wanted the query results to return all customer name regardless of whether they placed an order, you can use one of two types of OUTER JOINS, in this case, a LEFT JOIN:
SELECT CUSTOMERS.NAME, ORDERS.NAME
FROM CUSTOMERS
LEFT JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID
Which will be faster out of queries with explicit INNER JOIN and implicit one?
1. Implicit one will be faster.
2. i believe explicit inner join will be faster since in that case mysql doesn’t find the type of join. otherwise it will fetch all the records from both the tables and display it to user.
How do you maintain session in a load balancing system?
Using a common session save path in the php.ini file by mounting a shared location in each of the server.
What are the advantages of PHP5?
PHP 5, which was released earlier this week, is the first major release of PHP in years to focus on new features.
While one of the key goals behind PHP 3 was increasing PHP/FI 2.0’s performance and efficiency, at the same time it introduced a whole new set of functionality.
That was back in 1998.
PHP 4 provided another speed burst, as it introduced the Zend Engine. However, the majority of PHP 4’s changes were behind the scenes. Those features allowed more people than ever to use PHP, but it didn’t provide them with more tools to build their sites.
Finally, after six years, the community has revisited the legacy baggage that made tackling some problems unnecessarily difficult.
In particular, PHP 4’s version of object-oriented programming (OOP) lacks many features, the MySQL extension doesn’t support the new MySQL 4.1 client protocol, and XML support is a hodgepodge.
Fortunately, PHP 5 improves on PHP 4 in three major areas:
* Object-oriented programming
* MySQL
* XML
These items have all been completely rewritten, turning them from limitations into star attractions. While these changes alone warrant a new version of PHP, PHP 5 also provides a plethora of other new features.
In this article, I highlight seven of my favorite PHP 5 features. These features allow your PHP 5 code to frequently be shorter, more elegant, and more flexible than ever before.
1. Robust Support for Object-Oriented Programming
Ever since Zeev and Andi’s late-night OOP hack, PHP programmers have clamored for an increasing amount of OO features. However, neither PHP 3 nor PHP 4 truly incorporates objects into its core.
With PHP 5, PHP programmers can at last stop apologizing for PHP’s krufty OO support. It offers:
* Constructors
* Destructors
* Public, protected, and private properties and methods
* Interfaces
* Abstract classes
* Class type hints
* Static properties and methods
* Final properties and methods
* A whole suite of magical methods
Additionally, objects are now both assigned–and passed–by reference instead of by value, so the necessity to liberally sprinkle ampersands throughout your code is no more.
If you’re a person who enjoys web programming using objects and patterns, then these features alone will make your year. However, PHP 5’s just getting started.
2. A Completely Rewritten MySQL Extension
The MySQL database is PHP’s partner in crime. Many developers power their web sites with MySQL, yet the MySQL extension is showing its age. In retrospect, some design decisions weren’t the best solutions after all.
Also, the latest versions of MySQL, 4.1 and 5.0, introduce many new features, some of which require significant changes to the extension. As a result, PHP 5 comes with a completely new and improved MySQL extension. Dubbed MySQLi, for MySQL Improved. It offers:
* Prepared statements
* Bound input and output parameters
* SSL connections
* Multi-query functions
MySQLi even takes advantage of PHP 5’s new object-oriented support to provide an OO interface to MySQL. On top of that, the latest versions of MySQL now enable subselects, transactions, and replication.
3. A Suite of Interoperable XML Tools
PHP 5 fixes the major problems in PHP 4’s XML extensions. While PHP 4 allows you to manipulate XML, its XML tools are only superficially related. Each tool covers one part of the XML experience, but they weren’t designed to work together, and PHP 4 support for the more advanced XML features is often patchy.
Not so in PHP 5.
The new XML extensions:
* Work together as a unified whole.
* Are standardized on a single XML library: libxml2.
* Fully comply with W3 specifications.
* Efficiently process data.
* Provide you with the right XML tool for your job.
Additionally, following the PHP tenet that creating web applications should be easy, there’s a new XML extension that makes it simple to read and alter XML documents. The aptly named SimpleXML extension allows you to interact with the information in an XML document as though these pieces of information are arrays and objects, iterating through them with for-each loops, and editing them in place merely by assigning new values to variables.
In short, SimpleXML kicks ass!
If you know the document’s format ahead of time, such as when you’re parsing RSS files, REST results, and configuration data, SimpleXML is the way to go.
And if you’re a DOM fan, you’ll be pleasantly surprised with PHP 5’s DOM extension, which is light-years beyond what you’re using in PHP 4.
4. An Embedded Database with SQLite
While MySQL is greater than ever, it’s actually “too much database” for some jobs. SQLite is an embedded database library that lets you store and query data using an SQL interface without the overhead of installing and running a separate database application.
When your application needs a server-side storage mechanism but you can’t rely upon the presence of a specific database, turn to SQLite. It correctly handles locking and concurrent accesses, the two big headaches with homebrewed flat files.
PHP 5 bundles SQLite, providing developers with a database that’s guaranteed to work on all PHP 5 installations. Despite the name, SQLite is nowhere close to a “lite” database. It supports:
* Transactions
* Subqueries
* Triggers
* And many other advanced database features
You can even write user-defined functions in PHP and call them from within SQLite. This is by far and away the coolest feature available in any PHP database extension.
5. Cleaner Error Handling with Exceptions
PHP 5 offers a completely different model of error checking than what’s available in PHP 4. It’s called exception handling. With exceptions, you’re freed from the necessity of checking the return value of every function. Instead, you can separate programming logic from error handling and place them in adjoining blocks of code.
Exceptions are commonly found in object-oriented languages such as Java and C++. When used judiciously, they streamline code, but when used willy-nilly, they create spaghetti code.
Right now, only a few PHP extensions use exceptions, but they’re slowly being phased in. However, they’re available today for any PHP code you write.
6. A First-Class SOAP Implementation
SOAP is a key component of the fast-growing web services field. This extension lets developers create SOAP clients with or without a Web Services Description Language (WSDL) file, and also implement SOAP servers in PHP.
PHP 4’s SOAP support is only fair. While there are a few SOAP packages, the most mature ones are written in PHP instead of C. Therefore, they are slow, and you have to download and install them yourself.
With PHP 5, there’s finally a usable SOAP extension written in C. Currently, this extension implements most, but not all, of SOAP 1.2. This is a significant improvement over previous C extension, and future pieces will be added in time.
Particularly in comparison with .NET and Java, PHP’s SOAP support has always lagged behind the curve. Whether you love or hate SOAP, PHP needs to offer a first-class SOAP extension, and I’m excited to finally see some momentum in this direction.
7. Iterators
Iterators are a completely new PHP 5 feature. They allow you to use a for-each loop to cycle through different types of data: directory listings, database results, and even XML documents. SPL — Standard PHP Library — is a collection of iterators that provide this functionality and also filter, limit, cache, and otherwise modify iterator results.
Iterators are an incredibly handy way to abstract away messy details from your code.
For example, the DirectoryIterator turns directory iteration from this:
$dir = opendir($path);
while (false !== ($file = readdir($dir))) {
print "$filen";
}
closedir($dir);
Into this:
foreach (new DirectoryIterator($path) as $file) {
print "$filen";
}
There are no directory handles to mess about with, nor ugly conditions to check inside a while loop.
These are my top seven favorite features of PHP 5, but they’re by no means the only ones. Besides what I’ve already highlighted, PHP 5 also offers:
* Enhanced streams, wrappers, and filters.First introduced in PHP 4.3, streams are an underutilized part of PHP. They allow you to place a file interface on reading and writing data using protocol-specific objects known as wrappers. Streams also let you modify the data flowing through them by attaching filters.
* Code introspection using the Reflection classes.This set of classes lets you examine classes, methods, parameters, and more, to discover object attributes. It is now simple and easy to create PHP class browsers, debuggers, and other tools that rely on gathering details about objects and functions.
* Compliant HTML output thanks to Tidy.The Tidy extension makes it easy to ensure that your output is valid HTML and XHTML. Its smart parser brings even the most unruly of files into compliance with the latest W3C specifications.
* Superior command-line processing.The PHP5 command-line version now allows individual line processing, similar to Perl and awk. You can specify code to be run at the beginning, on, and at the end of each line in a file.
I hope you’ve found this quick tour around PHP 5 useful. As you can see, PHP 5 is leaps and bounds better than before. I’m sure you’ll find all sorts of cool ways to incorporate its features into your programs.
What are the Importance of Class autoloading?
Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).
In PHP 5, this is no longer necessary. You may define an __autoload function which is automatically called in case you are trying to use a class which hasn’t been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
Basically, you get a class name as a parameter in your __autoload() function, and using it you have to figure out the path to the actual class file and include it.
If all of the classes are at known paths in known folders, you might be able to find the class file path using simple string concatenation. However, if the folder structure is more complex, a convenient solution is to have a class name/class file path map (associative array), whether hand-made or generated:
function __autoload($classname)
{
$classes = array(
“NotFoundView” => APP_VIEW_DIR.”notFound/NotFoundView.class.php”,
“ErrorView” => APP_VIEW_DIR.”error/ErrorView.class.php”
// and so on
);
if (array_key_exists($classname, $classes)) require($classes[$classname]);
// using name as key, get the path and include the file
}
There can be several autoloading functions named differently, but then they have to be registered explicitly using spl_autoload_register(). Class methods can also be used.
These hacks are not very clean, but they help to bring PHP one little step closer to object- and library-oriented approach.
How can we refresh a page every 20 seconds wothout using javascript?
We can refresh the page with the help of meta refresh tag.
The meta tag belongs within the of your HTML document. When used to refresh the current page, the syntax looks like this:
meta equiv="refresh" content="20"
This is the amount of time, in seconds, until the browser should reload the current page.
Redirecting to a New Page
While the reload option is useful, it is usually not what people want from the meta refresh tag. To redirect to a new page, the syntax is nearly the same:
meta equiv="refresh" content="2;url="
The only difference is in the content attribute.
content=”2;url=http://webdesign.about.com”
The number is the time, in seconds, until the page should be redirected. Then, separated by a semi-colon (;) is the URL that should be loaded.
What is the difference between nodeName and tagName in DOM?
Both function can be applied for element but tagName cant be applied for text node since the text node is not a tag.
How to differentiate isset and empty?
isset -> this variable handling functions determine whether a variable is set . It checks whether a variable is set even though it is empty.
empty -> as the term itself has already given a sign that it would related to something thats empty, this variable handling functions determine whether a variable is empty. It checks whether a variable has a value whether its emptystring, zero0, or not set at all.
What’s the difference between the *connect and *pconnect database functions?
mysql_pconnect() acts very much like mysql_connect() with two major differences.
First, when connecting, the function would first try to find a (persistent) link 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 link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
These type of links is therefore called ‘persistent’.
What is the difference between Reply-to and Return-path in the headers of a mail function?
Reply-to: Reply-to is where to delivery the reply of the mail.
Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.
What is the purpose of the following files having extensions 1) frm 2) MYD 3) MYI. What these files contains?
In MySql, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension.
What are the advantages of stored procedures, triggers, indexes?
A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don’t need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side.
Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted.
Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.
What are the difference between abstract class and interface?
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.
What are the differences between require and include, include_once?
When a script require another script, if the required script does not exists, the script will not go farther but in include, the script will run till end of script if the included file does not exists.
include_once will include a file only once. On the other hand, include will try to include the file though the has already been included and will run the included file every time it has been included.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment