Saturday, May 7, 2011

PHP INTERVIEW QUESTIONS 70-80


71. What type of inheritance that PHP supports?


PHP Supports single inheritance.


72. How can increase the performance of MySQL select query?


Using LIMIT

Using INDEX

Using PRIMARY KEY


73. The structure of table view buyers is as follows:

+----------------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+----------------+-------------+------+-----+---------+----------------+

| user_pri_id | int(15) | | PRI | NULL | auto_increment |

| userid | varchar(10) | YES | | NULL | |

+----------------+-------------+------+-----+---------+----------------+

the value of user_pri_id the last row 2345 then What will happen in the following conditions?

Condition1: Delete all the rows and insert another row then. What is the starting value for this auto incremented field user_pri_id ,

Condition2: Delete the last row(having the field value 2345) and insert another row then. What is the value for this auto incremented field user_pri_id


Answer:

Condition1: 2346

Condition2:2346


  1. What are the advantages/disadvantages of MySQL and PHP?


Advantages:php
- Open Source, readily available (you can be using it today) and dual-
licensed - if you are doing non-profit work or not licensing, there is no cost.
- Very Easy to understand Syntax, some really cool features (arrays
are something else!)
- Interfaces very easily with Apache/MySQL
- Server side (no need to futz with client installs - only with
rendering issues if you use CSS).
- Lots of good source code out there to use and/or learn from, as well
as many useful libraries for working with PDFs, graphics, etc.
- Lots of good books and on-line help (php.net is great)
- Platform agnostic, can run on Windows Linux or Mac servers. Also
very scalable.
- Lots of hosting services have it ready to use, no special
configuration (except if you have special security needs)
- Pretty easy to access other web-based tools through PHP (i.e. google
maps, etc.)

Disadvantages of php

- If you want to do more than just HTML/CSS pages on the client you
need to also add javascript, java or other client-side language in
your output (goes for Perl and some other languages).
- The way browsers work make handling data and coding programs more
interesting (technically each page is a new run on the system, so you
have to manage your variables coming in and going out and between
pages. Not hard, just different.)
- Web programming (regardless of language) is open to security flaws
due to unimplemented or unknown vulnerabilities, takes a bit more
caution.

Advantages of MySQL Indexes

Generally speaking, MySQL indexing into database gives you three advantages:

Query optimization: Indexes make search queries much faster.

Uniqueness: Indexes like primary key index and unique index help to avoid duplicate row data.

Text searching: Full-text indexes in MySQL version 3.23.23, users have the opportunity to optimize searching against even large amounts of text located in any field indexed as such.

Disadvantages of MySQL indexes

When an index is created on the column(s), MySQL also creates a separate file that is sorted, and contains only the field(s) you're interested in sorting on.

Firstly, the indexes take up disk space. Usually the space usage isn’t significant, but because of creating index on every column in every possible combination, the index file would grow much more quickly than the data file. In the case when a table is of large table size, the index file could reach the operating system’s maximum file size.

Secondly, the indexes slow down the speed of writing queries, such as INSERT, UPDATE and DELETE. Because MySQL has to internally maintain the “pointers” to the inserted rows in the actual data file, so there is a performance price to pay in case of above said writing queries because every time a record is changed, the indexes must be updated. However, you may be able to write your queries in such a way that do not cause the very noticeable performance degradation

75. What is the difference between GROUP BY and ORDER BY in Sql?

The ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set by a specified column.

GROUP BY

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

  1. What is the difference between char and varchar data types?

CHAR

CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.

VARCHAR

Currently VARCHAR behaves exactly the same as VARCHAR2. However, this type should not be used as it is reserved for future usage.


  1. What is the functionality of md5 function in PHP?

With the md5 function you can encrypt your text with 32 character hexadecimal number.
For Ex. $str = 'apple'; echo md5($str);
this prints '1f3870be274f6c49b3e31a0c6728957f'
  1. How can I load data from a text file into a table?

Mysql > LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet; 
  1. How can we know the number of days between two given dates using MySQL?

    DATEDIFF(firstdate,seconddate)


80. How can we know the number of days between two given dates using PHP?

$days = (strtotime(date("date1")) - strtotime("date2")) / (60 * 60 * 24);

PHP INTERVIEW QUESTIONS 60-70

61. What are the other commands to know the structure of table using MySQL commands except explain command?

DESCRIBE table_name;


  1. How many tables will create when we create table, what are they?

If you create one table ,  then only one table with be created. 
But 3 files with be created namely tb_name.frm,tb_name.myi,tb_name.myd,


1. Data is stored in name.myd
2. Table structure is stored in name.frm
3. Index is stored in name.myi


63. What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?


1. Data is stored in name.myd
2. Table structure is stored in name.frm
3. Index is stored in name.myi


64. What is maximum size of a database in MySQL?


If the operating system or filesystem places a limit on the number of files in a directory,
MySQL is bound by that constraint. The efficiency of the operating system in handling large
numbers of files in a directory can place a practical limit on the number of tables in a
database. If the time required to open a file in the directory increases significantly as
the number of files increases, database performance can be adversely affected.
The amount of available disk space limits the number of tables.
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine
in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes).
With this larger allowed table size, the maximum effective table size for MySQL databases is
usually determined by operating system constraints on file sizes, not by MySQL internal
limits.
The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created
from several files. This allows a table to exceed the maximum individual file size.
The tablespace can include raw disk partitions, which allows extremely large tables.
The maximum tablespace size is 64TB.
The following table lists some examples of operating system file-size limits.
This is only a rough guide and is not intended to be definitive. For the most up-to-date
information, be sure to check the documentation specific to your operating system.
Operating System File-size Limit
Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)
Linux 2.4+ (using ext3 filesystem) 4TB
Solaris 9/10 16TB
NetWare w/NSS filesystem 8TB
Win32 w/ FAT/FAT32 2GB/4GB
Win32 w/ NTFS 2TB (possibly larger)
MacOS X w/ HFS+ 2TB


65. Give the syntax of Grant and Revoke commands?

grant all on table_name to user_name;
Revoke all on table_name from user_name;

GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY [password] All
privileges


REVOKE [rights] on [database/s] FROM [username@hostname] All privileges

66. Explain Normalization concept?

The normalization process involves getting our data to conform to three progressive normal
forms, and a higher level of normalization cannot be achieved until the previous levels have
been achieved (there are actually five normal forms, but the last two are mainly academic
and will not be discussed).

First Normal Form
The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows.
We want to ensure that there is no duplication of data in a given row, and that every column
stores the least amount of information possible (making the field atomic).

Second Normal Form
Where the First Normal Form deals with redundancy of data across a horizontal row,
Second Normal Form (or 2NF) deals with redundancy of data in vertical columns.
As stated earlier, the normal forms are progressive, so to achieve Second Normal Form,
your tables must already be in First Normal Form.

Third Normal Form

I have a confession to make; I do not often use Third Normal Form.
In Third Normal Form we are looking for data in our tables that is not fully dependant
on the primary key, but dependant on another value in the table

67.How can we find the number of rows in a table using MySQL?


Mysql : - select count(*) [tablename]; PHP :- mysql_num_rows(); 

68. How can we find the number of rows in a result set using PHP?

mysql_num_rows($rs) 

69. How many ways we can we find the current date using MySQL?

CURRENT_DATE() now() CURDATE( ) 

70. What are the advantages and disadvantages of Cascading Style Sheets?

Advantages of CSS:
1. CSS saves time:
When most of us first learn HTML, we get taught to set the font face, size, colour, style etc every time it occurs on a page. This means we find ourselves typing (or copying & pasting) the same thing over and over again. With CSS, you only have to specify these details once for any element. CSS will automatically apply the specified styles whenever that element occurs.
2. Pages load faster
Less code means faster download times.
3. Easy maintenance
To change the style of an element, you only have to make an edit in one place.
4.Superior styles to HTML
CSS has a much wider array of attributes than HTML.
Disadvantages of CSS:

1.Browsercompatibility

Browsers have varying levels of compliance with Style Sheets. This means that some Style Sheet features are supported and some aren't. To confuse things more, some browser manufacturers decide to come up with their own proprietary tags.