Join in mysql

Simple join in mysql
Select table1.columnname, table2.columnname from table1 join table2 ON table1.columnname=table2.columnname

Example-
Table 1- emp
    id name city designation departmentid


1 ajay sharavat noida manager 1



2 Vineet Butola noida developer 1



3 sandeep kumar noida developer 2



4 Sashank Singh delhi admin 2



5 Ambrish Singh noida developer 1



6 Aamir delhi support 1



7 vishal sharavat noida developer 3



8 vinay singh delhi developer 4



9 monu noida support 10

Table2-department

id name



1 It



2 support



3 HR



4 Sales



5 Marketing

Join Operation

SELECT emp.name, emp.designation, department.department_name
FROM `emp` JOIN department ON emp.departmentid = department.id


Output
name designation department_name
ajay sharavat manager It
Vineet Butola developer It
Ambrish Singh developer It
Aamir support It
sandeep kumar developer support
Sashank Singh admin support
vishal sharavat developer HR
vinay singh developer Sales


Inner Join and Cross joins performs the same operation. Just replace JOIN to INNER JOIN or CROSS JOIN.

LEFT JOIN



Triggers in Mysql

delimiter $$
CREATE trigger triggername before/after INSERT/UPDATE/DELETE ON tablename
FOR each
ROW
BEGIN
sql query
END

Example:
delimiter $$
CREATE trigger myfirsttrigger before INSERT ON emp
FOR each
ROW
BEGIN
INSERT INTO department VALUES ('', NEW.name);
END

Difference between mysql_fetch_array and mysql_fetch_row

Both are same but the difference is that in mysql_fetch_row we can retrieve values by using numeric asccociative example $name=$row[0], but in case of mysql_fetch_array we can retrive value by using table field name and numeric associative. Ex- $name=$row[0] and $name=$row['name'];

How many types of errors in php ?

There are four types of error in php
1. NOTICE
2. WARNING
3. FATAL
4. PARSE

Magic Methods in PHP

With PHP 5 Object Oriented Programming seems to becoming a reality in PHP but we all know that in PHP a variable can take any form depending on the data passed to it. Also PHP automatically creates variable and assigns values to it even is the variables are not defined. But in Object Oriented Programming all the data members/methods needs to be defined. To solve some of these problems in OOPS environment magic methods have been introduced in PHP5.

NOTE ON MAGIC METHODS:
  • Magic methods are the members functions that is available to all the instance of class
  • Magic methods always starts with “__”. Eg. __construct
  • All magic methods needs to be declared as public
  • To use magic method they should be defined within the class or program scope
Various Magic Methods used in PHP 5 are:
  • __construct()
  • __destruct()
  • __set()
  • __get()
  • __call()
  • __toString()
  • __sleep()
  • __wakeup()
  • __isset()
  • __unset()
  • __autoload()
  • __clone()

Objects in php oops

PHP is capable of functioning as an object-oriented programming language (or OOP). As such, it must be able to handle objects. An object is a data type that allows for the storage of not only data but also information on how to process that data. The data elements stored within an object are referred to as its properties, also sometimes called the attributes of the object. The information, or code, describing how to process the data compromises what are called the methods of the object.
Objects have two components to their construction. First, you must declare a class of object. It defines the structure of the object to be constructed. Then you instantiate the object, which means you declare a variable to be of a certain class and assign values to it appropriately.
Another way of looking at objects is that they allow you to create your own data types. You define the data type in the object class, and then you use the data type in instances of that class.
Yes, there is also an is_object() function to test whether a variable is on object instance.

find out the number of parameters passed into function

func_num_args() function returns the number of parameters passed in.

Defining a constant variable in php

Using define() directive, like define ("MYNAME", "Ajay Sharavat"); and to use constant varibale just
type echo MYNAME; or constant("MYNAME");

Difference between include and require

In case of include if the file doesn't exist it will give a warning but the rest of code will execute. But if we are using require then it will through a fatal error and will not execute the code.

Difference between mysql_connect and mysql_pconnect

mysql_connect is a normal mysql connection which opens and closes on each page. While mysql_pconnect is a persistant connection which will be open once and remained open throught the session.
mysql_pconnect does't work on high traffic because we have a limited number of mysql connections.
So using mysql_connect is good to use.

Difference between ereg_replace() and eregi_replace()

ereg_replace() is case sensitive while eregi_replace() is not. For example 'ajay' and 'AjAy' are different for ereg_replace() but same for eregi_replace().

Linux name resolution: /etc/resolv.conf

Name resolution means translating a string such as 'gateway.enterprise.net' into an IP address such as 194.72.194.1. When your machine is connected to the Internet, you need to be able to do this for addresses all over the world.
You do this through the Internet's Domain Name Service, which is a decentralised system for address translation. You will not usually run a nameserver yourself, unless you are managing extensive sub-networks. The nameserver is run by your ISP.

You have to tell your software where to find the name servers. This is done in /etc/resolv.conf, which looks like this:

domain lfix.co.uk
nameserver 194.72.192.1
nameserver 194.72.192.3
The domain is your own domain name, corresponding to the suffixes in /etc/hosts.
The nameservers are the primary and secondary nameservers of my ISP, Enterprise plc. The IP addresses are specified, rather than the names, because you would need a nameserver to translate the names to IP addresses.

If you try to use an address which is not in your local domain, the name resolver will ask the primary nameserver for its IP address. If that fails, it will try the secondary nameserver before giving up.

If PPP is not running, you will get the message "No route to host", meaning that there is no way to contact the nameserver.