PHP MySQL Interview Questions
PHP MySQL Interview Questions
1. All you need to do is compare the table to itself to find out which candidates are
duplicates. Do this by assigning aliases to the table so you can use it twice, once as
A and again as B, like this: delete from jobs where job_desc in (select a.job_desc
from jobs a, jobs b where a.job_desc = b.job_desc group by a.job_desc having
count(a.job_desc) >1);
41. Explain ACID rule of thumb for transactions?
1. Transaction must be: Atomic - it is one unit of work and does not dependent on
previous and following transactions.
2. Consistent - data is either committed or roll back, no in-between case where
something has been updated and something hasnt.
3. Isolated - no transaction sees the intermediate results of the current transaction.
4. Durable - the values persist if the data had been committed even if the system
crashes right after.
42. On executing the DELETE statement I keep getting the error about foreign key
constraint failing. What do I do?
1. What it means is that so of the data that youre trying to delete is still alive in
another table. Like if you have a table for universities and a table for students,
which contains the ID of the university they go to, running a delete on a university
table will fail if the students table still contains people enrolled at that university.
Proper way to do it would be to delete the offending data first, and then delete the
university in question. Quick way would involve running SET
foreign_key_checks=0 before the DELETE command and setting the parameter
back to 1 after the DELETE is done. If your foreign key was formulated with ON
DELETE CASCADE, the data in dependent tables will be removed automatically.
43. When would you use ORDER BY in DELETE statement?
1. When youre not deleting by row ID. Such as in DELETE FROM
techinterviews_com_questions ORDER BY timestamp LIMIT 1. This will delete the
most recently posted question in the table techinterviews_com_questions.
44. How can you see all indexes defined for a table?
1. SHOW INDEX FROM techinterviews_questions;
45. How would you change a table to InnoDB?
1. ALTER TABLE techinterviews_questions ENGINE innodb;
46. When you create a table, and then run SHOW CREATE TABLE on it, you
occasionally get different results than what you typed in. What does MySQL
modify in your newly created tables?
1. VARCHARs with length less than 4 become CHARs. CHARs with length more than 3
become VARCHARs. NOT NULL gets added to the columns declared as PRIMARY
KEYs. Default values such as NULL are specified for each column.
47. How do you get a portion of a string?
1. SELECT SUBSTR(title, 1, 10) from techinterviews_questions;
48. Whats the difference between CHAR_LENGTH and LENGTH?
1. The first is, naturally, the character count. The second is byte count. For the Latin
characters the numbers are the same, but theyre not the same for Unicode and
other encodings.
49. How do you get the month from a timestamp?
1. SELECT MONTH(techinterviews_timestamp) from techinterviews_questions;
50. How do you offload the time/date handling to MySQL?
1. SELECT DATE_FORMAT(techinterviews_timestamp, %Y-%m-%d) from
techinterviews_questions; A similar TIME_FORMAT function deals with time.
51. How do you add three minutes to a date?
Persistent refers to an objects ability to transcend time or space. A persistent object stores/saves
its state in a permanent storage system with out losing the information represented by the
object.
A non-persistent object is said to be transient or ephemeral. By default objects are considered as
non-persistent.
List out some of the object-oriented methodologies.
Object Oriented Development (OOD) (Booch 1991,1994).
Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991).
Object Modelling Techniques (OMT) (Rumbaugh 1991).
Object Oriented Software Engineering (Objectory) (Jacobson 1992).
Object Oriented Analysis (OOA) (Shlaer and Mellor 1992).
The Fusion Method (Coleman 1991).
What do you mean by analysis and design?
Analysis: It is the process of determining what needs to be done before how it should be done. In
order to accomplish this, the developer refers the existing systems and documents. So, simply it
is an art of discovery.
Design: It is the process of adopting/choosing the one among the many, which best accomplishes
the users needs. So, simply, it is compromising mechanism.
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 are the differences between require and include, include_once?
Anwser: 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.
Anwser: 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.
Anwser: All three are used to an include file into the current page.
If the file is not present, require(), calls a fatal error, while in include() does not.
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. It des not call a fatal
error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if
file not exists.
What is the Difference between GET and POST method?
The GET method, which was used in the example earlier, appends name/value pairs to the URL.
Unfortunately, the length of a URL is limited, so this method only works if there are only a few
parameters. The URL could be truncated if the form uses a large number of parameters, or if the
parameters contain large amounts of data. Also, parameters passed on the URL are visible in the
address field of the browser not the best place for a password to be displayed.
The alternative to the GET method is the POST method. This method packages the name/value
pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size
limitations on the forms output. It is also more secure.