What’s PHP
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications
Who is the father of PHP and explain the changes in PHP versions?
Rasmus Lerdorf in 1994
How many ways you can retrieve the data in the result set of mysql using PHP?
We can do it by 4 Ways
1. mysql_fetch_row ,
The mysql_fetch_row() function fetches one row from a result-set and returns it as an
enumerated array.
2. mysql_fetch_array ,
The mysql_fetch_array() function fetches a result row as an associative array, a numeric
array, or both.
3. mysql_fetch_object
The mysql_fetch_object() function returns the current row of a result set, as an object.
4. mysql_fetch_assoc
The mysql_fetch_assoc() function fetches a result row as an associative array.
How can we create a database using php and mysql?
<?php $query =mysql_query( "CREATE DATABASE phpcake");?>
What is the difference between mysql_fetch_object and mysql_fetch_array?
1. object is returned, instead of an array
2. In this you can only access the data by the field names
What are the differences between Get and post methods.
GET Method have some limit like only 2Kb data able to send for request But
in POST method unlimited data can we send.
What are the differences between require and include?
Both does the same functionality. It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement.
require will produce a fatal error (E_COMPILE_ERROR) and stop the script
include will only produce a warning (E_WARNING) and the script will continue
What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined.
What are the different functions in sorting an array?
Sort() ---- Sort an array
asort() --- Sort an array and maintain index association
arsort() --- Sort an array in reverse order and maintain index association
ksort() --- Sort an array by key
natsort(), natcasesort(),rsort(), usort(),array_multisort(), and uksort().
How can we know the count/number of elements of an array?
a) sizeof($urarray) This function is an alias of count()
B) count($urarray)
How can we find the number of rows in a table using MySQL?
SELECT COUNT(*) FROM table_name;
How can we know the number of days between two given dates using PHP?
$date1 = date("Y-m-d");
$date2 = "2006-08-15";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
what are magic methods?
Magic methods are the members functions that is available to all the instance of class Magic methods always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()
What Is a Session?A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.
There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
What is meant by PEAR in php?
PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install “packages”
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.
How to get the value of current session id?
session_id() returns the session id for the current session.
How can we know the number of days between two given dates using PHP?
Simple arithmetic:
$date1 = date(‘Y-m-d’);
$date2 = ’2006-07-01′;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ’2006-07-01′: $days”;
How can we repair a MySQL table?
REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED
This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.
What is the difference between $message and $$message?
$message is a simple variable whereas $$message is a reference variable. Example:
$user = ‘bob’
is equivalent to
$holder = ‘user’;
$$holder = ‘bob’;
What Is a Persistent Cookie?
A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
Temporary cookies can not be used for tracking long-term information.
Persistent cookies can be used for tracking long-term information.
Temporary cookies are safer because no programs other than the browser can access them.
Persistent cookies are less secure because users can open cookie files see the cookie values.
What does a special set of tags do in PHP?
The output is displayed directly to the browser.
How do you define a constant?
Via define() directive, like define (“MYCONSTANT”, 100);
What are the differences between require and include, include_once?
require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.
But require() and include() will do it as many times they are asked to do.
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.
What is meant by urlencode and urldecode?
urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.
How To Get the Uploaded File Information in the Receiving Script?
Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] – The file type determined by the browser.
$_FILES[$fieldName]['size'] – The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] – The temporary filename of the file in which the uploaded
file was stored on the server.
$_FILES[$fieldName]['error'] – The error code associated with this file upload.
The $fieldName is the name used in the <INPUT TYPE=FILE, NAME=fieldName>
What is the difference between mysql_fetch_object and mysql_fetch_array?
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
How can I execute a PHP script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications
Who is the father of PHP and explain the changes in PHP versions?
Rasmus Lerdorf in 1994
How many ways you can retrieve the data in the result set of mysql using PHP?
We can do it by 4 Ways
1. mysql_fetch_row ,
The mysql_fetch_row() function fetches one row from a result-set and returns it as an
enumerated array.
2. mysql_fetch_array ,
The mysql_fetch_array() function fetches a result row as an associative array, a numeric
array, or both.
3. mysql_fetch_object
The mysql_fetch_object() function returns the current row of a result set, as an object.
4. mysql_fetch_assoc
The mysql_fetch_assoc() function fetches a result row as an associative array.
How can we create a database using php and mysql?
<?php $query =mysql_query( "CREATE DATABASE phpcake");?>
What is the difference between mysql_fetch_object and mysql_fetch_array?
1. object is returned, instead of an array
2. In this you can only access the data by the field names
What are the differences between Get and post methods.
- GET requests can be cached
- GET requests remain in the browser history
- GET requests can be bookmarked
- GET requests should never be used when dealing with sensitive data
- GET requests have length restrictions
- GET requests should be used only to retrieve data
- POST requests are never cached
- POST requests do not remain in the browser history
- POST requests cannot be bookmarked
- POST requests have no restrictions on data length
GET Method have some limit like only 2Kb data able to send for request But
in POST method unlimited data can we send.
What are the differences between require and include?
Both does the same functionality. It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement.
require will produce a fatal error (E_COMPILE_ERROR) and stop the script
include will only produce a warning (E_WARNING) and the script will continue
What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined.
What are the different functions in sorting an array?
Sort() ---- Sort an array
asort() --- Sort an array and maintain index association
arsort() --- Sort an array in reverse order and maintain index association
ksort() --- Sort an array by key
natsort(), natcasesort(),rsort(), usort(),array_multisort(), and uksort().
How can we know the count/number of elements of an array?
a) sizeof($urarray) This function is an alias of count()
B) count($urarray)
How can we find the number of rows in a table using MySQL?
SELECT COUNT(*) FROM table_name;
How can we know the number of days between two given dates using PHP?
$date1 = date("Y-m-d");
$date2 = "2006-08-15";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);
what are magic methods?
Magic methods are the members functions that is available to all the instance of class Magic methods always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()
What Is a Session?A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.
There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
What is meant by PEAR in php?
PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install “packages”
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.
How to get the value of current session id?
session_id() returns the session id for the current session.
How can we know the number of days between two given dates using PHP?
Simple arithmetic:
$date1 = date(‘Y-m-d’);
$date2 = ’2006-07-01′;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ’2006-07-01′: $days”;
How can we repair a MySQL table?
REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED
This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.
What is the difference between $message and $$message?
$message is a simple variable whereas $$message is a reference variable. Example:
$user = ‘bob’
is equivalent to
$holder = ‘user’;
$$holder = ‘bob’;
What Is a Persistent Cookie?
A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
Temporary cookies can not be used for tracking long-term information.
Persistent cookies can be used for tracking long-term information.
Temporary cookies are safer because no programs other than the browser can access them.
Persistent cookies are less secure because users can open cookie files see the cookie values.
What does a special set of tags do in PHP?
The output is displayed directly to the browser.
How do you define a constant?
Via define() directive, like define (“MYCONSTANT”, 100);
What are the differences between require and include, include_once?
require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.
But require() and include() will do it as many times they are asked to do.
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.
What is meant by urlencode and urldecode?
urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.
How To Get the Uploaded File Information in the Receiving Script?
Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] – The file type determined by the browser.
$_FILES[$fieldName]['size'] – The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] – The temporary filename of the file in which the uploaded
file was stored on the server.
$_FILES[$fieldName]['error'] – The error code associated with this file upload.
The $fieldName is the name used in the <INPUT TYPE=FILE, NAME=fieldName>
What is the difference between mysql_fetch_object and mysql_fetch_array?
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
How can I execute a PHP script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
Comments
Post a Comment