Wednesday, October 7, 2009

Advanced Php Questions...

1. What is Indexing and how we create describe his merits and demerits.

Indexes are created on a per column basis. If you have a table with the columns: name, age, birthday and employeeID and want to create an index to speed up how long it takes to find employeeID values in your queries, then you would need to create an index for employeeID. When you create this index, MySQL will build a lookup index where employeeID specific queries can be run quickly. However, the name, age and birthday queries would not be any faster.

Indexes are something extra that you can enable on your MySQL tables to increase performance,c but they do have some downsides. When you create a new index MySQL builds a separate block of information that needs to be updated every time there are changes made to the table. This means that if you are constantly updating, inserting and removing entries in your table this could have a negative impact on performance.

If you are creating a new MySQL table you can specify a column to index by using the INDEX term as we have below. We have created two fields: name and employeeID (index).
CREATE TABLE employee_records (name VARCHAR(50),employeeID INT,
INDEX (employeeID) );

2. Upload the file use Ajax.

3. How to save the other image in ur server dynamically.

4. If we have a n number of category in table, how we find the main parent of the last node.

5. Describe the sequence of mysql query,
(a) primary->subquery->sub-sub query
(b) primary-> primary-> subquery.
(c) sub-subquery->subquery-> primary.

6. if a table contain a salary of employee, how following query return a result.
select salary form employee_table order by salary desc.
select salary form employee_table order by salary 2 desc.

give the answer.

7. what is NDB & how it configure?

8. If one table holds the data of employee, so what is return by following query after remove the parenthesis.

select (salary*2)+(3/salary)*(1.3+salary) from employee.

9. what is session and describe its default life time & how we increase it?

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

default time is 1440 seconds and after make a changes in php.ini session life time change.

10. difference between Innodb and Myissam table engine?
Innodb support the foreign key constraints myissam not.
Innodb support the rollback and commit myissam not.
myissam is default Engine of mysql it occupies less memory in compare of Innodb.

11. Diff between Primary key and Unique key.
primary must be integer and notnull, and only 1 primary in key in one table, many unique key assign in one table and not limitation of integer and not null.

12. MySql Injection

13. Crontab
cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.
Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.

14.how we find a size of file
filesize($filename);

15. what is union n mysql explain with example;
SQL UNION allows you to combine two or more result sets from select statements into a single result set. The usage of using SQL UNION is as follows:

SELECT statement UNION [DISTINCT | ALL] SELECT statement UNION [DISTINCT | ALL]

The column list of each individual SELECT statement must have the same data type. By default the UNION removes all duplicated rows from the result set even if you don’t explicit using DISTINCT after the UNION keyword. If you use UNION ALL explicitly, the duplicated rows will remain in the result set. Let’s practice with couples of examples which use SQL UNION. Suppose you want to combine customers and employees into one, you just perform the following query:
SELECT customerNumber id, contactLastname name FROM customers UNION SELECT employeeNumber id,firstname name FROM employees
Here is the excerpt of the output
    id  name          
------ ---------------
103 Schmitt
112 King
114 Ferguson
119 Labrune
121 Bergulfsen
124 Nelson
125 Piestrzeniewicz
128 Keitel
129 Murphy
131 Lee
In order to use ORDER BY to sort the result you have to use it after the last SELECTstatement. It would be the best to parenthesize all the SELECT statements and place ORDER BY after the last one. Suppose we use the want to sort the combination of employees and customers in the query above we can do as follows:
(SELECT customerNumber id,contactLastname name FROM customers) UNION (SELECT employeeNumber id,firstname name FROM employees) ORDER BY name,id
First it orders the result set by name and then by id What if we don’t use alias for each column in the SELECT statement? MySQL uses the column names in the first SELECTstatement as the label of the result therefore you can rewrite the query above as follows:
(SELECT customerNumber, contactLastname FROM customers) UNION (SELECT employeeNumber, firstname FROM employees) ORDER BY contactLastname, customerNumber
or you can also use the column position in the ORDER BY clause like following query
(SELECT customerNumber, contactLastname FROM customers) UNION (SELECT employeeNumber,firstname FROM employees) ORDER BY 2, 1


No comments: