Saturday, May 7, 2011

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.


PHP INTERVIEW QUESTIONS 50-60

51. List out some tools through which we can draw E-R diagrams for mysql. ?


Dbdesigner, conceptdraw etc.


52. How can I retrieve values from one database server and store them in other database server using PHP?

$db1 = mysql_connect(”host”,”user”,”pwd”) mysql_select_db(”db1″, $db1);
$res1 = mysql_query(”query”,$db1);
$db2 = mysql_connect(”host”,”user”,”pwd”, true) mysql_select_db(”db2″, $db2);
$res2 = mysql_query(”query”,$db2);
So mysql_connect has another optional boolean parameter which indicates
whether a link will be created or not. as we connect to the $db2 with this optional parameter
set to ‘true’, so both link will remain live.
now the following query will execute successfully.
$res3 = mysql_query(”query”,$db1);

53. List out the predefined classes in PHP?


Directory

The class from which dir is instantiated.

stdClass
Created by
typecasting to object.

__PHP_Incomplete_Class

Possibly created by unserialize().

Predefined classes as of PHP 5

These additional predefined classes were introduced in PHP 5.0.0.

exception
php_user_filter

Closure

The predefined final class Closure was introduced in PHP 5.3.0. It is used for internal implementation of anonymous functions.

The class has a constructor forbidding the manual creation of the object (issues E_RECOVERABLE_ERROR) and the __invoke method with the calling magic.


54. How can I make a script that can be bilanguage (supports English, German)?

1. create different files to store different languages    
eg: languages/eng.php
languages/ger.php
2. add constant variables in both the fileseg: languages/eng.php :: define('QUES','How are you');
eg: languages/ger.php :: contains define('QUES','Wie geht
es Ihnen');
3. in template page need to use the constant variable to
load the different language
eg: '<'div>'<'?php echo QUES;?>'<'/div>

4. load different files according to language request
5. ofcourse we need to use characters encoding UTF-8 in HTMl
or PHP pages.

55. What are the difference between abstract class and interface?

What is an Abstract Class?

An abstract class is a class with or without data members that provides some functionality and leaves the remaining functionality for its child class to implement. The child class must provide the functionality not provided by the abstract class or else the child class also becomes abstract.

Objects of an abstract and interface class cannot be created i.e. only objects of concrete class can be created

To define a class as Abstract, the keyword abstract is to be used e.g. abstract class ClassName { }

Example of Abstract Class

abstract class Furniture {      
private $height, width, length;
public
function setData($h, $w, $l)
{
$this->height = $h;
$this->width = $w;
$this->length = $l;
} //this function is declared as abstract and hence the function
//body will have to be provided in the child class
public abstract function getPrice();
} class BookShelf extends Furniture {
private $price; public setData($h, $w, $l, $p) {
parent::setData($h, $w, $l);
$this->price = $p;
}
//this is the function body of the parent abstract method
public function getPrice() { return $this->price; } }

Private methods cannot be abstract

If a method is defined as abstract then it cannot be declared as private (it can only be public or protected). This is because a private method cannot be inherited.

abstract class BaseClass {     
private
abstract function myFun();
}
class DerivedClass extends BaseClass {
public function myFun() {
//logic here
}
} $d = new DerivedClass(); //will cause error

What is an Interface?

An interface is a contract between unrelated objects to perform a common function. An interface enables you to specify that an object is capable of performing a certain function, but it does not necessarily tell you how the object does so, this means that it leaves for classes implementing an interface to define its behaviour.

To extend from an Interface, keyword implements is used.

We can have a class extend from more than one Interface.
interface Storable {         
function
getContentsAsText();
}
class
Document implements Storable {

public function getContentsAsText() {
return "This is Text of the Document\n";
}

}
class
Indexer {
public function readAndIndex(Storable $s) {
$textData = $s->getContentsAsText(); //do necessary logic to index

echo $textData;
}
}
$p = new Document();
$i = new Indexer();
$i->readAndIndex($p);
In the above example, Document and the Indexer class are two independant classes. The Indexer class is designed to index the contents of any text. Using the Storable interface above, we declare a method getContentsAsText() in the Document class. Because the Indexer class is only concerned with the TEXT, hence we can call getContentsAsText() method on the object of Document. This way any class if it implements the method getContentsAsText() can get indexed

Difference between Abstract Class and Interface

Abstract Classes

An abstract class can provide some functionality and leave the rest for derived class

The derived class may or may not override the concrete functions defined in base class

The child class extended from an abstract class should logically be related

Interface

An interface cannot contain any functionality. It only contains definitions of the methods

The derived class must provide code for all the methods defined in the interface

Completely different and non-related classes can be logically be grouped together using an interface

Subscribe below for article updates


56. How can we send mail using JavaScript?


function myfunction(form)

{

tdata=document.myform.tbox1.value;

location=?mailto:dep7abc@leeds.ac.uk?

subject=?+tdata+?/MYFORM?;

return true;

}


57. How can we repair a MySQL table?

REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE  tbl_name[, tbl_name]. [QUICK] [EXTENDED]
[USE_FRM]


REPAIR TABLE
repairs a possibly corrupted table. By default, it has the same effect as
myisamchk --recover tbl_name

58. What are the advantages of stored procedures, triggers, indexes?


1.Advsntsge of Stored Procedures:

Stored Procedures are precompiled one.

it is the group of sql statements.

stored procedure like a application programming.

stored procedure is a fast one because it is already precompiled.

stored procedure is the one is easy to maintain.


2.Advantage of Triggers:

Triggers is a special kind of procedure, the Main advantage of the trigger is automatic.

whenever the table affected by insert update or delete query that time the triggers will implicitely call.


3.Advantage of Indexs:

The Main advantage of the indexes is speed.

if the table having the indexes while selecting or filtering the row(s) 0r columns(s) ,the execution time very fast. but, if you use the indexed table the insert update and delete will be slow.


59. What is the maximum length of a table name, database name, and fieldname in MySQL?

Database: 64 
Table: 64
Column: 64
Index: 64
Constraint: 64
Stored Function or Procedure: 64
Trigger: 64
View: 64
Compound Statement Label: 16

60. How many values can the SET function of MySQL take?


MySQL SET function can take zero or more values, but at the maximum it can take 64 values.