What is the difference between Session and Cookie?
The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user's computers in the text file format. Cookies can't hold multiple variable while session can hold multiple variables..We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking
How to set cookies in PHP?
Setcookie("sample", "ram", time()+3600);
How to Retrieve a Cookie Value?
eg : echo $_COOKIE["user"];
How to create a session? How to set a value in session ? How to Remove data from a session?
Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];
Question: What are 3 different ways to connect with MySQL?
Following are 3 API with which we can connect to MySQL.
MySQL
MySQLI
PDO
Question: What is the best collation to use for MySQL?
utf8_general_ci: It is used for fast sorting but it is less accurate.
utf8_unicode_ci: It is used for better accuracy but little slow as compare to utf8_general_ci.
You can also use for specific languages like utf8_swedish_ci.
How can we submit a form without a submit button?
The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites).
how many ways we can retrieve the data in the result set of MySQL using PHP?
You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc
What is the difference between mysql_fetch_object and mysql_fetch_array?
mysql_fetch_object() is similar tomysql_fetch_array(), with one difference – an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
What are the differences between require and include, include_once and require_once?
The include() statement includes and evaluates the specified file.The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
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. As the name suggests, it will be included just once.include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
Can we use include ("abc.PHP") two times in a PHP page?
Yes we can use include() more than one time in any page though it is not a very good practice
What are the different tables present in MySQL, which type of table is generated when we are creating a table in the following syntax:create table employee (eno int(2),ename varchar(10)) ?
Total 7 types of tables we can create
1. CSV CSV storage engine
2. InnoDB Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables
3. MEMORY Hash based, stored in memory, useful for temporary tables
4. MyISAM MyISAM storage engine
5. MRG_MyISAM Collection of identical MyISAM tables
6. Aria Crash-safe tables with MyISAM heritage
7. SEQUENCE Generated tables filled with sequential values InnoDB is the default storage engine as of MySQL 5.0 and as a result if we do not specify the table name explicitly it will be assigned to the default engine.
Current versions of apache, PHP, and MySQL?
As of February, 2007 the current versions arePHP: php5.2.1
MySQL: MySQL 5.2
Apache: Apache 2.2.4
As on Date June 15,2017
Php =>7.1.6
Mysql=>5.7.18
Apache=> 2.4.25
Note: visit www.php.net,
http://dev.mysql.com/downloads/mysql/,
www.apache.org to get current
versions.
How can we encrypt and decrypt a data present in a MySQL table using MySQL?
AES_ENCRYPT () and AES_DECRYPT ()
The functions in this section perform encryption and decryption, and compression and uncompression:
encryption | decryption |
AES_ENCRYT() | AES_DECRYPT() |
ENCODE() | DECODE() |
DES_ENCRYPT() | DES_DECRYPT() |
ENCRYPT() | Not available |
MD5() | Not available |
OLD_PASSWORD() | Not available |
PASSWORD() | Not available |
SHA() or SHA1() | Not available |
Not available | UNCOMPRESSED_LENGTH() |
What are the different types of errors in PHP?
- E_ERROR: A fatal error that causes script termination
- E_WARNING: Run-time warning that does not cause script termination
- E_PARSE: Compile time parse error
- E_NOTICE: Run time notice caused due to error in code
- E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
- E_CORE_WARNING: Warnings that occur during PHP’s initial startup
- E_COMPILE_ERROR: Fatal compile-time errors indication problem with script
- E_USER_ERROR: User-generated error message
- E_USER_WARNING: User-generated warning message
- E_USER_NOTICE: User-generated notice message
- E_STRICT: Run-time notices
- E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
- E_ALL: Catches all errors and warnings
What is the functionality of the function strstr and stristr?
strstr:
Returns part of haystack string from the first occurrence of needle to the end of haystack.If needle is not found, returns FALSE.
If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
This function is case-sensitive. For case-insensitive searches, use stristr().
How can we convert the time zones using PHP?
$userTimezone = new DateTimeZone('America/New_York');
$gmtTimezone = new DateTimeZone('GMT');
$myDateTime = new DateTime('2016-03-21 13:14', $gmtTimezone);
$offset = $userTimezone->getOffset($myDateTime);
$myInterval=DateInterval::createFromDateString((string)$offset . 'seconds');
$myDateTime->add($myInterval);
$result = $myDateTime->format('Y-m-d H:i:s');
Echo $result;
What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system. unset() makes a variable undefined.
How can we register the variables into a session?
$_SESSION[’name’] = "Mizan";
How can we get the properties (size, type, width, height) of an image using PHP image functions?
To know the Image type use exif_imagetype () function To know the Image size use getimagesize () function To know the image width use imagesx () function To know the image height use imagesy() function t
How can we get the browser properties using PHP?
By using $_SERVER['HTTP_USER_AGENT'] variable.
What is the maximum size of a file that can be uploaded using PHP and how can we change this?
By default the maximum size is 2MB. and we can change the following setup at php.iniupload_max_filesize = 2M
How can we increase the execution time of a PHP script?
by changing the following setup at php.inimax_execution_time = 30 ; Maximum execution time of each script, in seconds
How many ways can we get the value of current session id?
session_id() returns the session id for the current session.
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.
How can we destroy the cookie?
Set the cookie in past.
How many ways we can pass the variable through the navigation between the pages?
- GET/QueryString
- POST
What is the difference between ereg_replace() and eregi_replace()?
eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.
What are the different functions in sorting an array?
Sort(), arsort(), asort(), ksort(), natsort(), natcasesort(), rsort(), usort(), array_multisort(), and uksort().
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($array).
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.
What is the maximum length of a table name, database name, and fieldname in MySQL?
The following table describes the maximum length for each type of identifier.
Identifier | Maximum Length (bytes) |
Database | 64 |
Table | 64 |
Column | 64 |
Index | 64 |
Alias | 255 |
How many values can the SET function of MySQL take?
MySQL set can take zero or more values but at the maximum it can take 64 values.