What is MVC and ZendFramework
Start Your Project
Creating a Layout
Creating Database and Model
Creating Controller Class and Controller Action
Creating Views
Finishing the project
Web Development
Get latest php interview questions
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
Table2-department
Join Operation
Output
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
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
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:
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
- __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
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.
Subscribe to:
Posts (Atom)