Interview Questions PHP Mysql
Interview Questions PHP Mysql
The echo can take more than one string for output and return 1.
4. What ways can we retrieve data? On the result sets of MySql using PHP?
There are four ways to retrieve and they are
mysql_fetch_row
mysql_fetch_assoc
mysql_fetch_array
mysql_fetch_object
MySQL – C, C++
SQL parser – Yacc.
Drivers
JSON Support
Graphical Tools
Flexible structure
High performance
Geo-Spatial Support
OLTP and Transactions
MySQL Enterprise Monitor
MySQL Enterprise Security
Manageable and easy to use
Replication & High-Availability
Manageability and Ease of Use
Replication and high availability
Security and storage management
Array
Object
Callable
Under Scalar types
Float
String
Integer
Boolean
Under Special types
Null
Resource
Yii 2
Symfony
CakePHP
CodeIgniter
Zend Framework
Fatal
E-Notices
E-Warnings
ISAM
Heap
Merge
MyISAM
INNO DB
It can gather the data from files, save those data to a file and also we can send those data through email.
One could delete, add, and modify elements within the database by using PHP.
Data Security
On-Demand Scalability
High Performance
Round-the-clock
Complete Workflow Control
Flexibility on Open Source
Comprehensive Transactional Support
28. What are the Magic Functions that are available in the PHP?
_destruct() _call() _get() _set() _isset() _unset() _construct() _sleep() _clone() _invoke() _to string _wakeup()
_set-state() _debuginfo()
32. What is the MIME types is required for sending the attachment mail?
Multipart/ mixed.
33. What are the various types of triggers that are possible in MySQL?
Before Insert
After Insert
Before Delete
After Delete
Before Update
After Update
BLOB
TINYBLOB
LONGBLOB
MEDIUMBLOB
TEXT
TINY TEXT
MEDIUM TEXT
LONGTEXT
Local Scope
Global Scope
Static Scope
43. What are the possible ways to pass the variable via navigation between pages?
o GET/QueryString
o POST
44. What is the one main distinction between PHP4 and PHP5
PHP5 can present various additional Object-Oriented Programming (OOP) features compared to PHP4.
45. What is the function used in removing the escape characters from the string?
stripslashes function.
Sort()
asort()
arsort()
ksort()
rsort()
usort()
natsort()
natcasesort()
uksort()
array_multisort()
47. Which method is used in sending the Simple Mail Transfer Protocol using PHP?
mail($EmailAddress, “Subject”, $MessageBody);.
48. From the statements that are given below which one is correct?
When $x = null;
53. Name the tools through which we could draw E- diagrams for MySQL.
Case Studio
Smart Draw
MySQL – 5.0
PHP – 5.1 Beta
Indexed Array
Associative Array
Multi-Dimensional Array
57. What are the built-in functions that will add value to the end of an array?
into_array()
inend_array()
array_push()
array_unshift()
Spaceship operator
Generator delegation
Anonymous classes
Closure:: call method
Group use declaration
Scalar type declarations
Return type declarations
Null coalescing operator (??)
Constant arrays using define()
Generator return expressions.
WordPress
Joomla
Magento
Drupal
61. How can you check whether the value of the given variable is number or not?
We can use is_numeric for checking whether they are number or not.
feof()
is_readable()
file_exists()
is_file_exists()
63. Which of the following is not a valid Simple XML Parser method?
simplexml_import_dom()
simplexml_import_sax()
simplexml_load_file()
simplexml_load_string()
The function simplexml_import_sax() is not valid.
68. From the below statements which of the following would produce the value of “83” as their
output?
71. From the below cURL which of them is not a valid parameter PHP?
CURLOPT_RETURNTRANSFER
CURLOPT_GET
CURLOPT_POST
CURLOPT_RETURNTRANSFER is not the valid cURL.
72. Name the functions that are used for searching the strings using the POSIX-style regular
expression?
sql_regcase()
eragi_replace()
ereg_replace()
spliti()
erag()
sql_regcase() and ereg_replace() functions are used.
geElementByName()
removeChild()
geElementById()
appendChild()
geElementById() is not a valid method in the PHP XML DOM.
78. What is the role of a LAMP in PHP?
It is the combination of Linux, Apache, PHP, and MySQL.
Private
Public
Protected
Table 64bytes
Index 64 bytes
Column 64 bytes
Database 64 bytes
Alias 255 bytes
Union
Union All
Minus
Intersect
crypt()
Mcrypt()
hash()
89. What are the various types of print functions that are available in PHP?
print() Function
printf() Function
echo() Function
print_r() Function
sprintf() Function
92. How would you protect the special characters in the query string?
We can protect using urlencode() function.
94. How would you remove the white-space from the start till the end of the $string variable?
We can use trim($string);
NOWO
CURRDATEO
CONCAT (X, Y)
DATEDIFF (X, Y)
1) What is MySQL?
MySQL is an open-source Database Management System (DBMS) for managing and organizing the data in a
tabular format, These data can be manipulated using MySQL programming language. It supported and
distributed by MySQL AB (now acquired by Oracle)
MySQL database server is reliable, fast and very easy to use. This software can be downloaded as freeware and
can be downloaded from the internet.
HEAP tables are present in memory and they are used for high speed storage on temporary
basis.
MySQL is open source software which is available at any time and has no cost involved.
MySQL is portable
GUI with command prompt.
Administration is supported using MySQL Query Browser
• Floating point numbers are stored in FLOAT with eight place accuracy and it has four bytes.
• Floating point numbers are stored in DOUBLE with accuracy of 18 places and it has eight bytes.
CHAR_LENGTH is character count whereas the LENGTH is byte count. The numbers are same for Latin
characters but they are different for Unicode and other encodings.
ENUMs and SETs are used to represent powers of two because of storage optimizations.
ENUM is a string object used to specify set of predefined values and that can be used during table creation.
Create table size(name ENUM('Small', 'Medium','Large');
REGEXP is a pattern match in which matches pattern anywhere in the search value.
SET
BLOB
ENUM
CHAR
TEXT
VARCHAR
Storage engines are called table types and data is stored in files using various techniques.
Technique involves:
Storage mechanism
Locking levels
Indexing
Capabilities and functions.
PHP Driver
JDBC Driver
ODBC Driver
C WRAPPER
PYTHON Driver
PERL Driver
RUBY Driver
CAP11PHP Driver
Ado.net5.mxj
TIMESTAMP column is updated with Zero when the table is created. UPDATE CURRENT_TIMESTAMP
modifier updates the timestamp field to current time whenever there is a change in other fields of the table.
18) What is the difference between primary key and candidate key?
Every row of a table is identified uniquely by primary key. There is only one primary key for a table.
Primary Key is also a candidate key. By common convention, candidate key can be designated as primary and
which can be used for any foreign key references.
It compress the MyISAM tables, which reduces their disk or memory usage.
Maximum size of Heal table can be controlled by MySQL config variable called max_heap_table_size.
22) What is the difference between MyISAM Static and MyISAM Dynamic?
In MyISAM static all the fields will have fixed width. The Dynamic MyISAM table will have fields like TEXT,
BLOB, etc. to accommodate the data types with various lengths.
Federated tables which allow access to the tables located on other databases on other servers.
Timestamp field gets the current timestamp whenever the row gets altered.
25) What happens when the column is set to AUTO INCREMENT and if you reach
maximum value in the table?
It stops incrementing. Any further inserts are going to produce an error, since the key has been used already.
26) How can we find out which auto increment was assigned on Last insert?
LAST_INSERT_ID will return the last value assigned by Auto_increment and it is not required to specify the
table name.
27) How can you see all indexes defined for a table?
UNIX_TIMESTAMP is the command which converts from MySQL timestamp to Unix timestamp
FROM_UNIXTIME is the command which converts from Unix timestamp to MySQL timestamp.
The = , <>, <=, <, >=, >,<<,>>, <=>, AND, OR, or LIKE operators are used in column comparisons in
SELECT statements.
No.
SELECT VERSION(), CURRENT_DATE;
SeLect version(), current_date;
seleCt vErSiOn(), current_DATE;
33) What is the difference between the LIKE and REGEXP operators?
A BLOB is a binary large object that can hold a variable amount of data. There are four types of BLOB –
TINYBLOB
BLOB
MEDIUMBLOB and
LONGBLOB
They all differ only in the maximum length of the values they can hold.
TINYTEXT
TEXT
MEDIUMTEXT and
LONGTEXT
They all correspond to the four BLOB types and have the same maximum lengths and storage requirements.
The only difference between BLOB and TEXT types is that sorting and comparison is performed in case-
sensitive for BLOB values and case-insensitive for TEXT values.
mysql_fetch_array() -Returns a result row as an associated array or a regular array from database.
37) Where MyISAM table will be stored and also give their formats of storage?
MyISAM
Heap
Merge
INNO DB
ISAM
ISAM is abbreviated as Indexed Sequential Access Method.It was developed by IBM to store and retrieve data
on secondary storage systems like tapes.
lnnoDB is a transaction safe storage engine developed by Innobase Oy which is a Oracle Corporation now.
DISTINCT is converted to a GROUP BY on all columns and it will be combined with ORDER BY clause.
SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
If you want to enter characters as HEX numbers, you can enter HEX numbers with single quotes and a prefix of
(X), or just prefix HEX numbers with (Ox).
A HEX number string will be automatically converted into a character string, if the expression context is a
string.
NOW () command is used to show current year,month,date with hours,minutes and seconds.
DATABASE
EVENT
FUNCTION
INDEX
PROCEDURE
TABLE
TRIGGER
USER
VIEW
BEFORE INSERT
AFTER INSERT
BEFORE UPDATE
AFTER UPDATE
BEFORE DELETE and
AFTER DELETE
TINYTEXT
TEXT
MEDIUMTEXT
LONGTEXT
CONCAT(A, B) – Concatenates two string values to create a single string output. Often used to combine two or
more fields into one single field.
MONTH(), DAY(), YEAR(), WEEK(), WEEKDAY() – Extracts the given data from a date value.
HOUR(), MINUTE(), SECOND() – Extracts the given data from a time value.
DATEDIFF(A, B) – Determines the difference between two dates and it is commonly used to calculate age
An ACL (Access Control List) is a list of permissions that is associated with an object. This list is the basis for
MySQL server’s security model and it helps in troubleshooting problems like users not being able to connect.
MySQL keeps the ACLs (also called grant tables) cached in memory. When a user tries to authenticate or run a
command, MySQL checks the authentication information and permissions against the ACLs, in a predetermined
order.
SQL Server is one of the database management systems (DBMS) and is designed by Microsoft. DBMS are
computer software applications with the capability of interacting with users, various other applications, and
databases. The objective of SQL Server is capturing and analyzing data and managing the definition, querying,
creation, updating, and administration of the database.
Learn PHP and MySQL from industry experts. Enroll now in PHP and MySQL Training
SQL Server is free and anyone can download and use it. The application uses SQL (Structured Query
Language), and it is easy to use.
MySQL provides cross-platform support, a wide range of interfaces for application programming, and has many
stored procedures like triggers and cursors that help in managing the database.
There are various advantages and disadvantages of using MySQL. Some of them are given below:
Advantages
MySQL helps in the secure management of databases. By using it, we can securely execute database
transactions.
It is fast and efficient in comparison to other database management systems as it supports varieties of storage
engines.
As its transaction processing is high, MySQL can execute millions of queries.
Besides, some of the features that make MySQL unique are deadlock identification, execution of multiple
transactions, efficient processing, and easy management.
Disadvantages
The logical architecture of MySQL is made of ‘connection manager’, ‘query optimizer’, and ‘pluggable
engines’.
In either Windows or POSIX systems, the named pipes provide ways of inter-process communications to
connect different processes running on the same machine. It dispenses with the necessity of using the network
stack, and data can be sent without affecting the performance. Servers set up named pipes to listen to requests.
The client process needs to know the specific pipe name to send the request.
The default port for MySQL Server is 3306. Another standard default port is 1433 in TCP/IP for SQL Server.
DDL is the abbreviation for Data Definition Language dealing with database schemas, as well as the description
of how data resides in the database. An example of this is the CREATE TABLE command. DML denotes Data
Manipulation Language which includes commands such as SELECT, INSERT, etc. DCL stands for Data
Control Language and includes commands like GRANT, REVOKE, etc.
10. What is a join in MySQL?
In MySQL, joins are used to query data from two or more tables. The query is made using the relationship
between certain columns existing in the table. There are four types of joins in MySQL.
Inner join returns rows if there is at least one match in both tables. Left join returns all the rows from the left
table even if there is no match in the right table. Right join returns all the rows from the right table even if no
matches exist in the left table. Full join would return rows when there is at least one match in the tables.
NOWO: The function for returning the current date and time as a single value
CURRDATEO: The function for returning the current date or time
CONCAT (X, Y): The function to concatenate two string values creating a single string output
DATEDIFF (X, Y): The function to determine the difference between two dates
Check out Intellipaat’s blog to get a fair understanding of SQL Optimization Techniques!
When a table is created, CHAR is used to define the fixed length of the table and columns. The length value
could be in the range of 1–255. The VARCHAR command is used to adjust the column and table lengths as
required.
Are you looking to become an MS SQL Server DBA Expert? Go through Intellipaat’s MS SQL Server DBA Training in
Hyderabad!
Basically, Heap tables are in-memory tables used for high-speed temporary storage. But, TEXT or BLOB fields
are not allowed within them. They also do not support AUTO INCREMENT.
15. What is the limit of indexed columns that can be created for a table?
The maximum limit of indexed columns that can be created for any table is 16.
16. What are the different types of strings used in database columns in MySQL?
In MySQL, the different types of strings that can be used for database columns are SET, BLOB, VARCHAR,
TEXT, ENUM, and CHAR.
18. What is the difference between primary key and unique key?
While both are used to enforce the uniqueness of the column defined, the primary key would create a clustered
index, whereas the unique key would create a non-clustered index on the column. The primary key does not
allow ‘NULL’, but the unique key does.
19. Is there an object-oriented version of MySQL library functions?
Storage tables are named table types. The data is stored in the files using multiple techniques such as indexing,
locking levels, capabilities, and functions.
Check out our comprehensive MySQL tutorial now and master the most widely used open-source relational
database management system.
21. What is the difference between the primary key and the candidate key?
The primary key in MySQL is used to identify every row of a table in a unique manner. For one table, there is
only one primary key. The candidate keys can be used to reference the foreign keys. One of the candidate keys
is the primary key.
22. What are the different types of tables in MySQL?
MyISAM is the default table that is based on the sequential access method.
Heap is the table that is used for fast data access, but the data will be lost if the table or the system crashes.
InnoDB is the table that supports transactions using the COMMIT and ROLLBACK commands.
BDB can support transactions similar to InnoDB, but the execution is slower.
23. What are the differences between a primary key and a foreign key?
Primary Key Foreign Key
It helps in the unique identification of data in It helps establish a link between
a database tables
There can be more than one foreign
There can be only one primary key for a table
key for a table
Primary key attributes cannot have duplicate Duplicate values are acceptable for
values in a table a foreign key
Null values are not acceptable Null values are acceptable
We can define primary key constraints for It cannot be defined for temporary
temporarily created tables tables
The primary key index is automatically The index is not created
created automatically
The use of ENUM will limit the values that can go into a table. For instance, a user can create a table giving
specific month values and other month values would not enter into the table.
Thinking of opting for one of the Database Courses? Intellipaat is the right choice for you!
25. What are the TRIGGERS that can be used in MySQL tables?
26. What is the difference between LIKE and REGEXP operators in MySQL?
Information that is provided on the slow query log could be huge in size. The query could also be listed over a
thousand times. In order to summarize the slow query log in an informative manner, one can use the third-party
tool ‘pt-query-digest’.
In such cases when the password is lost, the user should start the DB with skip-grants-table and then change the
password. Thereafter, with the new password, the user should restart the DB in a normal mode.
29. How to resolve the problem of the data disk that is full?
When the data disk is full and overloaded, the way out is to create and soft link and move the .frm and the .idb
files into that link location.
30. What is the difference between the DELETE TABLE and TRUNCATE TABLE
commands in MySQL?
Basically, DELETE TABLE is a logged operation, and every row deleted is logged. Therefore, the process is
usually slow. TRUNCATE TABLE also deletes rows in a table, but it will not log any of the rows deleted. The
process is faster here in comparison. TRUNCATE TABLE can be rolled back and is functionally similar to the
DELETE statement without a WHERE clause.
There are four types of joins in MySQL. Inner join returns the rows if there is at least one match in two tables.
Left join returns all the rows from the left table even if there is no match in the right table. Right, join returns all
the rows from the right table even if no matches exist in the left table. Full join would return rows when there is
at least one match in the tables.
For this, it is necessary to review the layered architecture and determine hardware and software configuration
dependencies with respect to the application put to test.
A transaction is a logical unit of work where either all or none of the steps should be performed. ACID is the
abbreviation for Atomicity, Consistency, Isolation, and Durability that are properties of any transaction.
36. How can one restart SQL Server in the single user or the minimal configuration modes?
The command line SQLSERVER.EXE used with ‘–m’ will restart SQL Server in the single-user mode and the
same with ‘–f’ will restart it in the minimal configuration mode.
BLOBs are binary large objects holding huge data. Four types of BLOBs are TINYBLOB, BLOB,
MEDIBLOB, and LONGBLOB. TEXT is a case-sensitive BLOB. Four types of TEXT are TINY TEXT,
TEXT, MEDIUMTEXT, and LONG TEXT.
Yes. The syntax for using MySQL with Linux operating system is as follows:
etc/init.d/mysqlstart
Timestamp in SQL Server helps in row versioning. Row versioning is a type of concurrency that allows
retaining the value until it is committed in the database. It shows the instant time of any event. It consists of
both the date and time of the event. Also, timestamp helps in backing up data during the failure of a transaction.
While we insert, update, or delete a record, the date and time automatically get inserted.
As the name suggests, mysqldump is used to dump one or more created databases. It performs backups for data
or transfers the data from SQL Server to another. Also, it helps in producing the initial database schema by
logical backups. Moreover, unlike triggers, mysqldump does not backup the stored procedures or functions by
default.
Syntaxes
For a single database:
mysqldump [options] db_name [tables]
Every organization has some crucial data specific to its business. This data needs secure access so that any
consequence due to data loss can be avoided. For this, organizations create a sequence of permissions that are
linked to various data objects. These lists are known as the access control list (ACL).
ACL serves as the basis for the server’s security that helps troubleshoot the connection problems for users.
These are also known as grant tables that are cached by MySQL. MySQL verifies a user for authentication and
grants permissions in a sequence when the user executes a command.
If you have any doubts or queries related to SQL, get them clarified from SQL experts on our SQL
Community!