• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

PHP Interview Questions Answers

Question - 1 : - What are "GET" and "POST"?

Answer - 1 : - GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input." Major Difference In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string. Ex: Assume we are logging in with username and password. GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password']. POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password']. POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).

Question - 2 : - How can I embed a java programme in php file and what changes have to be done in php.ini file?

Answer - 2 : - 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

Question - 3 : - Would you initialize your strings with single quotes or double quotes?

Answer - 3 : - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

Question - 4 : - How can we get the properties (size, type, width, height) of an image using php image functions?

Answer - 4 : - To know the image size use getimagesize() function To know the image width use imagesx() function To know the image height use imagesy() function  

Question - 5 : - How can we change the data type of a column of a table?

Answer - 5 : - 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]

Question - 6 : - if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

Answer - 6 : - 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.

Question - 7 : - How can we find the number of rows in a result set using PHP?

Answer - 7 : - 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";

Question - 8 : - What is the functionality of the function strstr and stristr?

Answer - 8 : - strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com". stristr() is idential to strstr() except that it is case insensitive.

Question - 9 : - How to reset/destroy a cookie ?

Answer - 9 : - 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');

Question - 10 : - How To Create a Table?

Answer - 10 : - If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script: <?php include "mysql_connection.php"; $sql = "CREATE TABLE Tech_links (" . " id INTEGER NOT NULL" . ", url VARCHAR(80) NOT NULL" . ", notes VARCHAR(1024)" . ", counts INTEGER" . ", time TIMESTAMP DEFAULT sysdate()" . ")"; if (mysql_query($sql, $con)) { print("Table Tech_links created.\n"); } else { print("Table creation failed.\n"); } mysql_close($con); ?> Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this: Table Tech_links created.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners