PHP/MYSQL Important Questions

1.     Which syntax is used to describe elements in CSS?
2.     The latest version of CSS is
3.     Which of the following is the default positioning elements with CSS?
4.     Which method is used to remove a binding?
5.     Which of the following is not the value the key property will hold if the key is a function key?
6.     Which is the code that asks for the set of all div elements in a document?
7.     Which of the following is an equivalent replacement of $(document).ready(f)?
8.     Which is the correct way to write a JavaScript array?
9.     Choose the client-side JavaScript object?
10.   Which one of the following statements instantiates the mysqli class?
11.   Which of the following is not an SQL aggregate function?
12.   What does the DESC keyword do in the following query?SELECT * FROM MY_TABLE WHERE ID > 0 ORDER BY ID, NAME DESC
13.   Use the ………….. to delete the data inside the table, and not the table itself?
14.   Can joins be nested?
15.   What is true about joining tables through an equijoin?
16.   Which of the following functions can be used to determine the integrity of a string?
17.   What is the difference between print() and echo()?
18.   Which of the conditional statements is/are supported by PHP?i) if statementsii) if-else statementsiii) if-elseif statementsiv) switch statements
19.   If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
20.   Which function is used to erase all session variables stored in the current session?
21.   Which one of the following statements should you use to set the session username to Nachi?
22.   Which one of the following statements can be used to select the database?
23.   Which one of the following databases has PHP supported almost since the beginning?
24.   Which one of the following methods is responsible for sending the query to the database?
25.   Which one of the following method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE query?
26.   The URLs in the administrative links won’t mean anything to admin.php unless you modify ___.
27.   What will be the output of the following PHP code?<?php $str = addslashes(‘What does “yolo” mean?’);echo($str); ?>
28.   What will be the output of the following PHP code?<?php$str = “Hello world. It’s a beautiful day.”;print_r (explode(” “,$str));?>
29.   Which one of the following PHP functions can be used to build a function that accepts any number of arguments?
30.   <?php$user = array(“Ashley”, “Bale”, “Shrek”, “Blank”);for ($x = 0; $x < count($user); $x++) {if ($user[$x] == “Shrek”)continue;printf ($user[$x]); }?>
31.   Which one of the following statements should be used to include a file?
32.   What is the default value of max_execution_time directive? This directive specifies how many seconds a script can execute before being terminated.
33.   Suppose all web material is located within the directory /home/www. To prevent users from viewing and manipulating files such as /etc/password, which one of the following statements should you use?
34.   <?phpdefine(“GREETING”, “PHP is a scripting language”, true);echo GREETING;echo “<br>”echo GREETING;?>
35.   The focus and blur events are also part of
36.   The high-level events among the following events are
37.  When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
38.  CSS allows you to specify your own selectors called
39.  Which selector is used to specify a style for a group of elements ?
40.  Which browser can supports the transition property?
41.  he transition-duration property is in fact the only property required
42.  Which of followng statement is more suitable if you want to output a blend of static text and dynamic information stored within one or several variables?
43.  To produce the output6 I love the summer time, Which of the ofllowing statement should be used?
44.  To use inline styles you use the style attribute in the …………… tag
45.  The <link> tag goes inside
46.  How do you insert a comment in a CSS file?
47.  How many types of levels in style sheets?
48.  To use inline styles you use the style attribute in the …………… tag
49.  XHTML stands for:
50.  Choose the client-side JavaScript object:
51.  CSS allows you to specify your own selectors called
52.  Which selector is used to specify a style for a group of elements ?
53.  Which attribute will be defines a unique name for the text field?
54.  Which default technique is used to the method attribute?
55.  The method attribute specifies two methods
56.  What does vlink mean ?
57.  CSS provided the basic styles such as
58.  Which property gets provide the increments or decrements the space between characters?
59.  Which is the correct syntax of css border?
60.  Which CSS property can provide to add an effect when changing from one style to another,without using Flash animations or javascript?
61.  Which browser can supports the transition property?
62.  he transition-duration property is in fact the only property required
63.  Which properties is used to change the case of the text?
64.  The text-decoration are:
65.  How do you insert a comment in a CSS file?
66.  How many types of levels in style sheets?
67.  To use inline styles you use the style attribute in the …………… tag
68.  XHTML stands for:
69.  Choose the client-side JavaScript object:
70.  CSS allows you to specify your own selectors called
71.  Which selector is used to specify a style for a group of elements ?
72.  Which attribute will be defines a unique name for the text field?
73.  Which default technique is used to the method attribute?
74.  The method attribute specifies two methods
75.  What does vlink mean ?
76.  CSS provided the basic styles such as
77.  Which property gets provide the increments or decrements the space between characters?
78.  Which is the correct syntax of css border?
79.  Which CSS property can provide to add an effect when changing from one style to another,without using Flash animations or javascript?
80.  Which browser can supports the transition property?
81.  he transition-duration property is in fact the only property required
82.  Which properties is used to change the case of the text?
83.  The text-decoration are:
84.  What does fopen() function do in PHP?
85.  Variables are case-sensitive in PHP?
86.  Which of the following is used to add single comments in PHP?
87.  What will be the output of the following PHP code ?<?php$a = 12;–$a;echo $a++;?>
88.  <?php $x; echo “$x”; ?>
89.  Which two predefined variables are used to retrieve information from forms?
90.  <?php $On_e = 1; $tw_o = 2; $thre_e = 3; $fou_r = 4;echo $on_e / $tw_o + $thre_e / $fou_r; ?>
91.  <?php$x = 3, 4, 5, 6;echo “$x”;?>
92.  Which one of the following should not be used while sending passwords or other sensitive information?
93.  Which directive determines whether PHP scripts on the server can accept file uploads?
94.  Which superglobal stores a variety of information pertinent to a file uploaded to the server via a PHP script?
95.  How many items are available in the $_FILES array?
96.  Which property gets provide the increments or decrements the space between characters?
97.  Which function is used to determine whether a file was uploaded?
98.  Which CSS property can provide to add an effect when changing from one style to another,without using Flash animations or javascript?
99.  The filesize() function returns the file size in ___.
100.               Which one of the following PHP function is used to determine a file’s last access time?
101.               Which one of the following function is capable of reading a file into a string variable?
102.               Which one of the following function is capable of reading a specific number of characters form a file?
103.               Which one of the following function outputs the contents of a string variable to the specified resource?
104.               Php supports all four different ways of delimiting. In this context identify the false statement
105.               Which of followng statement is more suitable if you want to output a blend of static text and dynamic information stored within one or several variables?
106.               To produce the output6 I love the summer time, Which of the ofllowing statement should be used?
107.               For integer data type PHP 5 and earlier supported
108.               Which of the following statement produce different output
109.               <?php $age = array(“Harry” => “21”, “Ron” => “23”,”Malfoy” => “21”);array_change_key_case($age, CASE_UPPER);array_pop($age);print_r($age);?>
110.               <?php$a = array(12, 5, 2);echo(array_product($a));?>
111.               Php supports all four different ways of delimiting. In this context identify the false statement
112.               When uploading a file if the UPLOAD_ERR-OK contains value 0 it means
113.               Which of the following data type is compound datatype supported by PHP
114.               When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
115.               To work with remote files in PHP you need to enable
116.               The function setcookie( ) is used to
117.               Which function is used to determine whether a file was uploaded?
118.               The difference between include() and require()
119.               A variable $word is set to “HELLO WORLD”, which of the following script returns in title case?
120.               Which of the following variables is not a predefined variable?
121.               Which of the following is not true?
122.               The left associative dot operator (.) is used in PHP for
123.               Which one of the following function outputs the contents of a string variable to the specified resource?

Most Asking PHP Interview Questions

  1. How can we register the variables into a session?
    session_register($session_var);
    $_SESSION[‘var’] = ‘value’;

 

  1. What is the difference between characters 23 and \x23? 
    The first one is octal 23, the second is hex 23.

 

  1. With a heredoc syntax, do I get variable substitution inside the heredoc contents?
    Yes.

 

  1. How can we submit form without a submit button?
    We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code,

we can call the document.form.submit() function to submit the form.

    For example: <input type=button value=”Save” onClick=”document.form.submit()”>

 

  1. How can we create a database using PHP and mysql?
    We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.

 

  1. How many ways we can retrieve the date in result set of mysql using php?
    As individual objects so single record or as a set or arrays.

 

  1. Can we use include (“abc.php”) two times in a php page “makeit.php”?
    Yes.

 

  1. For printing out strings, there are echo, print and printf. Explain the differences.
    Echo is the most primitive of them, and just outputs the contents following the construct to the screen.

    Print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful

output and FALSE if it was unable to print out the string.

However, you can pass multiple parameters to echo, like:

<?php echo ‘Welcome ‘, ‘to’, ‘ ‘, ‘techpreparations!’; ?> 

and it echo will output the string “Welcome to techpreparations!”

 

print does not take multiple parameters.

 

It is also generally argued that echo is faster, but usually the speed advantage is negligible,and might

not be  there for future versions of PHP. printf is a function, not a construct, and allows such advantages as

formatted output, but it’s the slowest way to print out data out of echo, print and printf.

 

  1. I am writing an application in PHP that outputs a printable version of driving directions. It  

   contains some long sentences, and I am a neat freak, and would like to make sure that no line 

   exceeds 50 characters. How do I accomplish that with PHP? 
On large strings that need to be formatted according to some length specifications, use wordwrap() or

chunk_split().

 

  1. What’s the output of the ucwords function in this example?
    $formatted = ucwords(“TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS”);
    print $formatted;
    What will be printed is TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS.
    ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.

 

11.What’s the difference between htmlentities() and htmlspecialchars()? 
htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

 

12.How can we extract string “abc.com” from a string “mailto:info@abc.com?subject=Feedback”  using regular expression of PHP? 
$text = “mailto:info@abc.com?subject=Feedback”;
preg_match(‘|.*@([^?]*)|’, $text, $output);
echo $output[1];

Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].

 

13.So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

 

 

14.How can we destroy the session, how can we unset the variable of a session?
session_unregister() – Unregister a global variable from the current session
session_unset() – Free all session variables

 

15.What are the different functions in sorting an array? 
Sorting functions in PHP:
asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()

 

16.How can we know the count/number of elements of an array? 
2 ways:
a) sizeof($array) – This function is an alias of count()
b) count($urarray) – This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1.

 

17.How many ways we can pass the variable through the navigation between the pages? 
At least 3 ways:

1. Put the variable into session in the first page, and get it back from session in the next page.
2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.
3. Put the variable into a hidden form field, and get it back from the form in the next page.

 

18.What is the maximum length of a table name, a database name, or a field name in MySQL? 
Database name: 64 characters
Table name: 64 characters
Column name: 64 characters

 

19.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.

 

20.What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command? 
DESCRIBE table_name;

 

21.How can we find the number of rows in a table using MySQL?
Use this for MySQL

SELECT COUNT(*) FROM table_name;

 

22.What’s the difference between md5(), crc32() and sha1() crypto on PHP? 
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions

.

23.How can we find the number of rows in a result set using PHP? 
Here is how can you find the number of rows in a result set in PHP:

$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;

 

24.How many ways we can we find the current date using MySQL? 
SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();

 

25.Give the syntax of GRANT commands? 
The generic syntax for GRANT is as following

GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]

Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.

We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.

 

26.Give the syntax of REVOKE commands?
The generic syntax for revoke is as following

REVOKE [rights] on [database] FROM [username@hostname]

Now rights can be:
a) ALL privileges
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.

We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name.

 

27.What is the difference between CHAR and VARCHAR data types? 
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, “Hello!” will be stored as “Hello! ” in CHAR(10) column.

VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, “Hello!” will be stored as “Hello!” in VARCHAR(10) column.

 

28.How can we encrypt and decrypt a data present in a mysql table using mysql?
AES_ENCRYPT() and AES_DECRYPT()

 

29.Will comparison of string “10” and integer 11 work in PHP? 
Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

 

30.What is the functionality of MD5 function in PHP? 
string md5(string)

It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.

 

31.How can I load data from a text file into a table? 
The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:

a) Data must be delimited
b) Data fields must match table columns correctly

 

32.How can we know the number of days between two given dates using MySQL? 
Use DATEDIFF()

SELECT DATEDIFF(NOW(),’2006-07-01′);

 

33.How can we change the name of a column of a table? 
This will change the name of column:

ALTER TABLE table_name CHANGE old_colm_name new_colm_name

34.How can we change the data type of a column of a table? 
This will change the data type of a column:

ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]

35.What is the difference between GROUP BY and ORDER BY in SQL? 
To sort a result, use an ORDER BY clause.
The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any).
ORDER BY [col1],[col2],…[coln]; Tells DBMS according to what columns it should sort the result. If two rows will have the same value in col1 it will try to sort them according to col2 and so on.
GROUP BY [col1],[col2],…[coln]; Tells DBMS to group (aggregate) results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average.

36.What is meant by MIME? 
Answer 1:
MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file (for example image)
Some examples of MIME types:
audio/x-ms-wmp
image/png
application/x-shockwave-flash

Answer 2:
Multipurpose Internet Mail Extensions.
WWW’s ability to recognize and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types

 

37.How can we know that a session is started or not?
A session starts by session_start() function.
This session_start() is always declared in header portion. it always declares first. then we write session_register().

38.What are the differences between  mysql_fetch_array(),  mysql_fetch_object(),  mysql_fetch_row()?
Answer 1:
mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array.
mysql_fetch_object() -> Fetch a result row as an object.
mysql_fetch_row() -> Fetch a result set as a regular array().

Answer 2:
The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row[‘name’], $row[’email’], etc.). mysql_fetch_object() returns an object ($row->name, $row->email, etc.).

39.If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why? 
Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser.
40.What are the MySQL database files stored in system ? 
Data is stored in name.myd
Table structure is stored in name.frm
Index is stored in name.myi
41.What is the difference between PHP4 and PHP5? 
PHP4 cannot support oops concepts and Zend engine 1 is used.

PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.

42.Can we use include(abc.PHP) two times in a PHP page makeit.PHP”? 
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)
there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

43.What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()? 
mysql_fetch_array – Fetch a result row as an associative array and a numeric array.

mysql_fetch_object – Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows

mysql_fetch_row() – Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

44.What is meant by nl2br()? 
Anwser1:
nl2br() inserts a HTML tag <br> before all new line characters \n in a string.

echo nl2br(“god bless \n you”);

output:
god bless<br>
you

45.How can we encrypt and decrypt a data presented in a table using MySQL? 
You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:

AES_ENCRYPT(str, key_str)
AES_DECRYPT(crypt_str, key_str)

46.How can I retrieve values from one database server and store them in other database server using PHP? 
For this purpose, you can first read the data from one server into session variables. Then connect to other server and simply insert the data into the database.

 

47.Who is the father of PHP and what is the current version of PHP and MYSQL?
Rasmus Lerdorf.
PHP 5.1. Beta
MySQL 5.0

48.In how many ways we can retrieve data in the result set of MYSQL using PHP? 
mysql_fetch_array – Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc – Fetch a result row as an associative array
mysql_fetch_object – Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array

49.What are the functions for IMAP? 
imap_body – Read the message body
imap_check – Check current mailbox
imap_delete – Mark a message for deletion from current mailbox
imap_mail – Send an email message

50.What are encryption functions in PHP? 
CRYPT()
MD5()

51.What is the difference between htmlentities() and htmlspecialchars()? 
htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)
htmlentities() – Convert ALL special characters to HTML entities

52.What is the functionality of the function htmlentities? 
htmlentities() – Convert all applicable characters to HTML entities
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

53.How can we get the properties (size, type, width, height) of an image using php image functions? 
To know the image size use getimagesize() function
To know the image width use imagesx() function
To know the image height use imagesy() function

54.How can we increase the execution time of a php script? 
By the use of void set_time_limit(int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out. .

  1. HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?
    Answer 1:
    Create a full backup of your database: shell> mysqldump tab=/path/to/some/dir opt db_name
    Or: shell> mysqlhotcopy db_name /path/to/some/dir
    The full backup file is just a set of SQL statements, so restoring it is very easy:shell> mysql “.”Executed”;

    Answer 2:
    To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory
    ’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory

    mysqldump: Dumping Table Structure and Data

    Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
    -t, no-create-info
    Don’t write table creation information (the CREATE TABLE statement).
    -d, no-data
    Don’t write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!

56.How to set cookies? 
setcookie(‘variable’,’value’,’time’)
;
variable – name of the cookie variable
value – value of the cookie variable
time – expiry time
Example: setcookie(‘Test’,$i,time()+3600);

Test – cookie variable name
$i – value of the variable ‘Test’
time()+3600 – denotes that the cookie will expire after an one hour

 

57.How to reset/destroy a cookie ?
Reset a cookie by specifying expire time in the past:
Example: setcookie(‘Test’,$i,time()-3600); // already expired time

Reset a cookie by specifying its name only
Example: setcookie(‘Test’);

 

58.What types of images that PHP supports ? 
Using imagetypes() function to find out what types of images are supported in your PHP engine.
imagetypes() – Returns the image types supported.
This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

 

59.Check if a variable is an integer in JAVASCRIPT ?
var myValue =9.8;
if(parseInt(myValue)== myValue)
alert(‘Integer’);
else
alert(‘Not an integer’);

60.Tools used for drawing ER diagrams. 
Case Studio
Smart Draw

61.How can I know that a variable is a number or not using a JavaScript? 
Answer 1:
bool is_numeric( mixed var)
Returns TRUE if var is a number or a numeric string, FALSE otherwise.

Answer 2:
Definition and Usage
The isNaN() function is used to check if a value is not a number.

Syntax
isNaN(number)

Parameter Description
number Required. The value to be tested

62.How can we submit from without a submit button? 
Trigger the JavaScript code on any event ( like onSelect of drop down list box, onfocus, etc ) document.myform.submit(); This will submit the form.

63.How many ways can we get the value of current session id? 
session_id() returns the session id for the current session.

64.How can we destroy the cookie? 
Set the cookie with a past expiration time.

65.What are the current versions of Apache, PHP, and MySQL? 
PHP: PHP 5.1.2
MySQL: MySQL 5.1
Apache: Apache 2.1

66.What are the reasons for selecting LAMP (Linux, Apache, MySQL, Php) instead of combination of other software programs, servers and operating systems? 
All of those are open source resource. Security of  Linux is very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.

67.What are the features and advantages of OBJECT ORIENTED PROGRAMMING? 
One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.

68.How can we get second of the current time using date function? 
$second = date(“s”);

 

69.What is the use of friend function?
Friend functions

Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.
class mylinkage
{
private:
mylinkage * prev;
mylinkage * next;

protected:
friend void set_prev(mylinkage* L, mylinkage* N);
void set_next(mylinkage* L);

public:
mylinkage * succ();
mylinkage * pred();
mylinkage();
};

void mylinkage::set_next(mylinkage* L) { next = L; }

void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }

Friends in other classes
It is possible to specify a member function of another class as a friend as follows:
class C
{
friend int B::f1();
};
class B
{
int f1();
};

It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.
class A
{
friend class B;
};

Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.

70.How can we get second of the current time using date function? 
$second = date(“s”);

71.What is the maximum size of a file that can be uploaded using PHP and how can we change this? 
You can change maximum size of a file set upload_max_filesize variable in php.ini file

72.How can I make a script that can be bilingual (supports English, German)? 
You can change char set variable in above line in the script to support bi language

.

73.What are the difference between abstract class and interface? 
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

74.What are the advantages of stored procedures, triggers, indexes? 
A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don’t need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side. Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted. Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.

75.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

76.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

77.What’s the difference between accessing a class method via -> and via ::? 
:: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.

78.What are the advantages and disadvantages of CASCADE STYLE SHEETS? 
External Style Sheets
Advantages
Can control styles for multiple documents at once Classes can be created for use on multiple HTML element types in many documents Selector and grouping methods can be used to apply styles under complex contexts

Disadvantages
An extra download is required to import style information for each document The rendering of the document may be delayed until the external style sheet is loaded Becomes slightly unwieldy for small quantities of style definitions

Embedded Style Sheets

Advantages
Classes can be created for use on multiple tag types in the document Selector and grouping methods can be used to apply styles under complex contexts No additional downloads necessary to receive style information

Disadvantage
This method can not control styles for multiple documents at once

Inline Styles

Advantages
Useful for small quantities of style definitions Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods

Disadvantages
Does not distance style information from content (a main goal of SGML/HTML) Can not control styles for multiple documents at once Author can not create or control classes of elements to control multiple element types within the document Selector grouping methods can not be used to create complex element addressing scenarios

79.What type of inheritance that php supports? 
In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’.

 

80.How can increase the performance of MySQL select query?
We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.

81.How can we change the name of a column of a table? 
MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name
or,
ALTER TABLE tableName CHANGE OldName newName.

82.When you want to show some part of a text displayed on an HTML page in red font color? What different possibilities are there to do this? What are the advantages/disadvantages of these methods? 
There are 2 ways to show some part of a text in red:

1. Using HTML tag <font color=”red”>
2. Using HTML tag <span style=”color: red”>

83.When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)? 
When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder.

A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML document.

84.What are the different ways to login to a remote server? Explain the means, advantages and disadvantages? 
There is at least 3 ways to logon to a remote server:
Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.

85.Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag. 
Try this: /href=”([^”]*)”/i

86.How can I use the COM components in php?
The COM class provides a framework to integrate (D)COM components into your PHP scripts.
string COM::COM( string module_name [, string server_name [, int codepage]]) – COM class constructor.

Parameters:

module_name: name or class-id of the requested component.
server_name: name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com, allow_dcom has to be set to TRUE in php.ini.
codepage – specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.
Usage:
$word->Visible = 1; //open an empty document
$word->Documents->Add(); //do some weird stuff
$word->Selection->TypeText(“This is a test…”);
$word->Documents[1]->SaveAs(“Useless test.doc”); //closing word
$word->Quit(); //free the object
$word->Release();
$word = null;.

87.How many ways we can give the output to a browser? 
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser

88.What is the default session time in php and how can I change it? 
The default session time in php is until closing of browser

89.What changes I have to do in php.ini file for file uploading? 
Make the following line uncomment like:
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\apache2triad\temp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

 

90.How to store the uploaded file to the final location?
move_uploaded_file ( string filename, string destination)

This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

91.Explain about Type Juggling in php? 
PHP does not require (or support) explicit type definition in variable declaration; a variable’s type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.

An example of PHP’s automatic type conversion is the addition operator ‘+’. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.

$foo += 2; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a float (3.3)
$foo = 5 + “10 Little Piggies”; // $foo is integer (15)
$foo = 5 + “10 Small Pigs”; // $foo is integer (15)

If the last two examples above seem odd, see String conversion to numbers.
If you wish to change the type of a variable, see settype().
If you would like to test any of the examples in this section, you can use the var_dump() function.
Note: The behavior of an automatic conversion to array is currently undefined.

Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being “f”, or should “f” become the first character of the string $a? The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes “f”, the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:

92.How can I embed a java programme in php file and what changes have to be done in php.ini file? 
There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.
The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.

Example Code: 

getProperty(‘java.version’) . ”; echo ‘Java vendor=’ . $system->getProperty(‘java.vendor’) . ”; echo ‘OS=’ . $system->getProperty(‘os.name’) . ‘ ‘ . $system->getProperty(‘os.version’) . ‘ on ‘ . $system->getProperty(‘os.arch’) . ‘ ‘; // java.util.Date example $formatter = new Java(‘java.text.SimpleDateFormat’, “EEEE, MMMM dd, yyyy ‘at’ h:mm:ss a zzzz”); echo $formatter->format(new Java(‘java.util.Date’)); ?>

The behaviour of these functions is affected by settings in php.ini.
Table 1. Java configuration options
Name
Default
Changeable
java.class.path
NULL
PHP_INI_ALL
Name Default Changeable
java.home
NULL
PHP_INI_ALL
java.library.path
NULL
PHP_INI_ALL
java.library
JAVALIB
PHP_INI_ALL

93.Explain the ternary conditional operator in PHP? 
Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

94.What’s the difference between include and require? 
It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

96.How many ways can we get the value of current session id? 
session_id() returns the session id for the current session.

Download PDF Files

Google Map Add

<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>Untitled Document</title>
<script type=”text/javascript” src=”jquery.min.js”></script>
<script type=”text/javascript” src=”http://www.google.fr/jsapi”></script&gt;
<script type=”text/javascript”>
google.load(“maps”, “3.4”, {
other_params: “sensor=false&language=en”
});
</script>
<script type=”text/javascriptsrc=”https://rawgithub.com/Tilotiti/jQuery-Google-Map/master/jquery.googlemap.js“></script>
</head>

<body>

<div id=”map” style=”width: 300px; height: 300px;”></div>
<script type=”text/javascript”>
$(function() {
$(“#map”).googleMap();

$(“#map”).addMarker({
coords: [48.895651, 2.290569],
icon: ‘http://cdacjaipur.in/images/cdac-logo.gif&#8217;, // Icon URL,
url: ‘http://cdacjaipur.in/&#8217; // Link URL
});

})
</script>
</body>
</html>

Scrollto Top

<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”></script&gt;
<script>
$(document).ready(function(){

//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$(‘.scrollToTop’).fadeIn();
} else {
$(‘.scrollToTop’).fadeOut();
}
});

//Click event to scroll to top
$(‘.scrollToTop’).click(function(){
$(‘html, body’).animate({scrollTop : 0},800);
return false;
});

});
</script>
<style>
.scrollToTop{
background:#036;color:#fff; padding:10px;
text-decoration: none;
position:fixed;
top:75px;
right:40px;
display:none;
}
.scrollToTop:hover{
text-decoration:none;
background:#036;color:#fff; padding:10px;
}
</style>
<title>Untitled Document</title>
</head>

<body>
<p>Deepak Parihar</p>

<p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p><p>Deepak Parihar</p>

<a href=”#” class=”scrollToTop”>Top</a>
</body>
</html>

Games

<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>Untitled Document</title>
<style>
body
{
width: 100%;
margin: 0 auto;
padding: 0;
}

.bubb
{
position: absolute;
width:30px;
height: 30px;
font: bold 14px verdana;
background-color: yellow;
text-align: center;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
vertical-align: middle;
padding: 5px;
}

#score
{
font-size:46px;
top: 25px;
right: 50px;
display: none;
text-align:right;
}

#start{
width: 50px;
padding: 10px 15px;
text-align: center;
font:bold 15px arial;
background-color: #dedede;
color: #000;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
position: absolute;
}

#start:hover{
cursor: pointer;
}
</style>
<script src=”jquery.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function()
{
// Getting screen resolutions and positioning the start button
var width = screen.width – 100;
var height = screen.height – 200;
var code = 0;
$(‘#start’).css(
{
“top” : (height/2)+’px’,
“left” : (width/2)+’px’
});

$(‘#start’).click( function()
{
$(this).fadeOut(‘slow’);
$(‘#score’).show();
genLetter();
});

// Dealing KeyEvents and fading out matched bubble
$(document).keydown( function(event)
{
var keycode = event.keyCode;
$(‘.bubb’+keycode).animate(
{
“top” : height+”px”, “opacity” : 0
}, ‘slow’);

$(‘.bubb’+keycode).fadeOut(‘slow’).hide( ‘slow’, function()
{
code += 20;
$(‘#score’).html(code);
$(this).remove();
}
);
});

// Generating a random alphabet between A-Z
function genLetter()
{
var color = randomColor();
var k = Math.floor(Math.random() * ( 90 – 65 + 1 )) + 65;
var ch = String.fromCharCode(k);
var top = Math.floor(Math.random() * height );
var left = Math.floor(Math.random() * width );
$(‘body’).append(‘<span class=”bubb bubb’+ k +'” style=”left: ‘+ left +’; top: ‘+ top +’; background-color:’+ color +'”>’+ ch +'</span>’);
setTimeout(genLetter, 1000);
}

// Generating a random color
function randomColor()
{
var color = ”;
var values = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘0’];
for (c = 0; c < 6; c++)
{
no = Math.floor(Math.random() * 15);
color += values[no];
}
return color;
}
});

</script>
</head>

<body>
<div id=”score”>0</div>
<div id=”start”>Start</div>
</body>
</html>

Character Count

$(document).ready(function() {
$(“#textarea”).keyup(function(){
$(“#count”).text(“Characters left: ” + (500 – $(this).val().length));
});

OR

#bar
{
background-color:#5fbbde;
width:0px;
height:16px;
}
#barbox
{
float:right;
height:16px;
background-color:#FFFFFF;
width:100px;
border:solid 2px #000;
margin-right:3px;
-webkit-border-radius:5px;-moz-border-radius:5px;
}
#count
{
float:right; margin-right:8px;
font-family:’Georgia’, Times New Roman, Times, serif;
font-size:16px;
font-weight:bold;
color:#666666
}
#contentbox
{
width:450px; height:50px;
border:solid 2px #006699;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}

Untitled Document

$(document).ready(function()
{
$(“#contentbox”).keyup(function()
{
var box=$(this).val();
var main = box.length *100;
var value= (main / 145);
var count= 145 – box.length;

if(box.length <= 145)
{
$('#count').html(count);
$('#bar').animate(
{"width": value+'%',}, 1);
}
else
{
alert(' Full ');
}
return false;
});

});

145

Mouse Move Event

<script language=”JavaScript”>
function function2() {
myX.innerHTML = window.event.offsetX;
myY.innerHTML = window.event.offsetY;
mySX.innerHTML = window.event.screenX;
mySY.innerHTML = window.event.screenY;
mySH.innerHTML = myDiv.scrollHeight;
mySW.innerHTML = myDiv.scrollWidth;
}
function function1() {
mySL.innerHTML = myDiv.scrollLeft;
myST.innerHTML = myDiv.scrollTop;
}
</script>
<p>
<b>X Coordinate:</b>
<span id=”myX”>0</span>
</p>
<p>
<b>Y Coordinate:</b>
<span id=”myY”>0</span>
</p>
<p>
<b>Screen X:</b>
<span id=”mySX”>0</span>
</p>
<p>
<b>Screen Y:</b>
<span id=”mySY”>0</span>
</p>
<p>
<b>Scroll Height:</b>
<span id=”mySH”>0</span>
</p>
<p>
<b>Scroll Width:</b>
<span id=”mySW”>0</span>
</p>
<p>
<b>Scroll Left:</b>
<span id=”mySL”>0</span>
</p>
<p>
<b>Scroll Top:</b>
<span id=”myST”>0</span>
</p>
<div id=”myDiv”
onmousemove=”function2();”
onscroll=”function1();”
style=”border:solid; width:200; height:50; overflow:scroll;”>
</div>

DOM EXAMPLES

<!DOCTYPE html>
<html>
<head>
<script>
function insRow(id)
{
var x = document.getElementById(id).insertRow(0);
var y = x.insertCell(0);
var z = x.insertCell(1);
var d = x.insertCell(2);
y.innerHTML = z.innerHTML = d.innerHTML = “New”;
}
function deleteRow(id) {
document.getElementById(id).deleteRow(0);
}
</script>
</script>
</head>

<body>
<table id=”myTable” style=”border: 1px solid black”>
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
<td>Row1 cell3</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
<td>Row1 cell3</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
<td>Row1 cell3</td>
</tr>
</table>
<input type=”button” onclick=”insRow(‘myTable’)” value=”Insert row”>
<input type=”button” value=”Delete” onclick=”deleteRow(‘myTable’)”>
</p>
document.getElementById(‘myImg’).src=’compman.gif’
<img id=”myImage” onclick=”changeImage()” src=”pic_bulboff.gif” width=”100″ height=”180″>

<p>Click the light bulb to turn on/off the light.</p>

<script>
function changeImage() {
var image = document.getElementById(‘myImage’);
if (image.src.match(“bulbon”)) {
image.src = “pic_bulboff.gif”;
} else {
image.src = “pic_bulbon.gif”;
}
}
</script>
<script type=”text/javascript”>
function appendMessage() {
var oNewP = document.createElement(“p”);
var oText = document.createTextNode(“www.java2s.com”);
oNewP.appendChild(oText);
document.body.appendChild(oNewP);
}
</script>
<input type=”button” value=”rrr” onClick=”appendMessage()” >
<P>Hello World!</p>
</body>
</html>