0% found this document useful (0 votes)
15 views

GRM - 7B - Php&mysql - Viva (Q&A)

PHP is a server-side scripting language commonly used for web development. It supports databases like MySQL and has several data types including integers, floats, booleans, strings, arrays, and objects. Variables in PHP must begin with a letter or underscore, and key functions include print, echo, count(), header(), isset(), and parameterized functions. There are different types of loops like for, while, and foreach. PHP allows including files, setting cookies, managing sessions on the server-side, and connecting to MySQL databases.

Uploaded by

rojamani ganta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

GRM - 7B - Php&mysql - Viva (Q&A)

PHP is a server-side scripting language commonly used for web development. It supports databases like MySQL and has several data types including integers, floats, booleans, strings, arrays, and objects. Variables in PHP must begin with a letter or underscore, and key functions include print, echo, count(), header(), isset(), and parameterized functions. There are different types of loops like for, while, and foreach. PHP allows including files, setting cookies, managing sessions on the server-side, and connecting to MySQL databases.

Uploaded by

rojamani ganta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

7-B Web Applications Development using PHP& MYSQL

1) What is PHP?
PHP stands for Hypertext Preprocessor. It is an open source server-side scripting
language which is widely used for web development. It supports many databases like
MySQL, Oracle, Sybase, Solid, PostgreSQL, generic ODBC etc.
2) Who is known as the father of PHP?
Rasmus Lerdorf

3) What was the old name of PHP?


The old name of PHP was Personal Home Page.
4) What is "print" in PHP?
PHP print output a string. It is a language construct not a function. So the use of
parentheses is not required with the argument list. Unlike echo, it always returns 1.

5.What is the difference between "echo" and "print" in PHP?


Echo can output one or more string but print can only output one string and always
returns 1.
Echo is faster than print because it does not return any value.

6) How a variable is declared in PHP?


A PHP variable is the name of the memory location that holds data. It is temporary
storage.
Syntax:
1. $variableName=value;
Q. What are the rules for naming a PHP variable?
The following rules are needed to be followed while naming a PHP variable:
 Variable names must begin with a letter or underscore character.
 A variable name can consist of numbers, letters, underscores but you cannot
use characters like + , – , % , ( , ) . & , etc.

7) How many data types are there in PHP?


PHP data types are used to hold different types of data or values. There are 8 primitive
data types which are further categorized in 3 types:
here are 8 data types in PHP which are used to construct the variables:
1. Integers − are whole numbers, without a decimal point, like 4195.
2. Doubles − are floating-point numbers, like 3.14159 or 49.1.
3. Booleans − have only two possible values either true or false.
4. NULL − is a special type that only has one value: NULL.
5. Strings − are sequences of characters, like ‘PHP supports string operations.’
6. Arrays − are named and indexed collections of other values.
7. Objects − are instances of programmer-defined classes, which can package up
both other kinds of values and functions that are specific to the class.
8. Resources − are special variables that hold references to resources external to
PHP.
Q8) What are the different loops in PHP?
For, while, do-while and for each.

Q9) What is the use of count() function in PHP?


The PHP count() function is used to count total elements in the array, or something an
object.

10) What is the use of header() function in PHP?


The header() function is used to send a raw HTTP header to a client. It must be called
before sending the actual output. For example, you can't print any HTML element before
using this function.

11) What does isset() function?


The isset() function checks if the variable is defined and not null.

12) Explain PHP parameterized functions.


PHP parameterized functions are functions with parameters. You can pass any number of
parameters inside a function. These given parameters act as variables inside your function.
They are specified inside the parentheses, after the function name. Output depends upon
dynamic values passed as parameters into the function.
13) How many types of array are there in PHP?
There are three main types of arrays that are used in PHP.
 Indexed arrays: These are arrays that contain numerical data. Data access and
storage are linear.
 Associative arrays: There are arrays that contain strings for indexing elements.
 Multidimensional arrays: These are arrays that contain more than one index and
dimension.
14) Explain some of the PHP array functions?
There are many array functions in PHP:
o array()
o array_change_key_case()
o array_chunk()
o count()
o sort()
o array_reverse()
o array_search()
o array_intersect()
15) What is the difference between indexed and associative array?
The indexed array holds elements in an indexed form which is represented by number
starting from 0 and incremented by 1. For example:
1. $season=array("summer","winter","spring","autumn");
The associative array holds elements with name. For example:
1. $salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000");
16) Explain some of the PHP string functions?
There are many array functions in PHP:
o strtolower()
o strtoupper()
o ucfirst()
o lcfirst()
o ucwords()
o strrev()
o strlen()
17) What are the ways to include file in PHP?
PHP allows you to include file so that page content can be reused again. There are two
ways to add the file in PHP.
1. include
2. require
18) Differentiate between require and include?
Require and include both are used to include a file, but if data is not found include sends
warning whereas require sends Fatal error.
19)Explain setcookie() function in PHP?
PHP setcookie() function is used to set cookie with HTTP response. Once the cookie is
set, you can access it by $_COOKIE superglobal variable.
20) What is a session?

PHP Engine creates a logical object to preserve data across subsequent HTTP requests,
which is known as session.
Sessions generally store temporary data to allow multiple PHP pages to offer a complete
functional transaction for the same user.
21) What is PHP session_start() and session_destroy() function?
PHP session_start() function is used to start the session. It starts new or resumes the
current session. It returns the current session if the session is created already. If the session
is not available, it creates and returns new sessions.
More details...

22) What is the difference between session and cookie?


The main difference between session and cookie is that cookies are stored on user's
computer in the text file format while sessions are stored on the server side.
Cookies can't hold multiple variables, on the other hand, Session can hold multiple
variables.
23 How to read a file in PHP?
PHP provides various functions to read data from the file. Different functions allow you to
read all file data, read data line by line, and read data character by character.
PHP file read functions are given below:
o fread()
o fgets()
o fgetc()
24) How to write in a file in PHP?
PHP fwrite() and fputs() functions are used to write data into file. To write data into a file,
you need to use w, r+, w+, x, x+, c or c+ mode.
25) How to upload file in PHP?
The move_uploaded_file() function is used to upload file in PHP.
bool move_uploaded_file ( string $filename , string $destination )
26) How to download file in PHP?
The readfile() function is used to download the file in PHP.
27)How do you connect MySQL database with PHP?
There are two methods to connect MySQL database with PHP. Procedural and object-
oriented style.
28) How to create connection in PHP?
The mysqli_connect() function is used to create a connection in PHP.
1. resource mysqli_connect (server, username, password)
29) What is the use of the function 'imagetypes()'?
imagetypes() gives the image format and types supported by the current version of GD-
PHP.
30) What are include() and require() functions?
The Include() function is used to put data of one PHP file into another PHP file. If errors
occur, then the include() function produces a warning but does not stop the execution of
the script, and it will continue to execute.
The Require() function is also used to put data of one PHP file to another PHP file. If
there are any errors, then the require() function produces a warning and a fatal error and
stops the script.

31) What is Cookies? How to create cookies in PHP?


A cookie is used to identify a user. A cookie is a little record that the server installs on the
client's Computer. Each time a similar PC asks for a page with a program, it will send the
cookie as well. With PHP, you can both make and recover cookie value.
Some important points regarding Cookies:
1. Cookies maintain the session id generated at the back end after verifying the
user's identity in encrypted form, and it must reside in the browser of the machine
2. You can store only string values not object because you can't access any object
across the website or web apps
3. Scope: - Multiple pages.
4. By default, cookies are temporary and transitory cookie saves in the browser
only.
5. By default, cookies are URL particular means Gmail isn't supported in Yahoo
and the vice versa.
6. Per site 20 cookies can be created in one website or web app
7. The Initial size of the cookie is 50 bytes.
8. The Maximum size of the cookie is 4096 bytes.
32)How does the ‘foreach’ loop work in PHP?
The foreach statement is a looping construct used in PHP to iterate and loop through the
array data type. The working of foreach is simple; with every single pass of the value,
elements get assigned a value and pointers are incremented. This process is repeated until
the end of the array.
The following is the syntax for using the foreach statement in PHP:
foreach(array)
{
Code inside the loop;
}
33). Differentiate between require() and require_once() functions.
require() require_once()
The inclusion and evaluation of files Includes files if they are not included before
Preferred for files with fewer functions Preferred when there are a lot of functions
34)What are the data types present in PHP?
9. PHP supports three types of data handling, and they are as shown in the
following table:
Scalar Data Types Compound Data Types Special Data Types
● Boolean ● Array ● NULL
● Integer<> ● Object ● Resource
● Float
● String
35) ow are comments used in PHP?
There are two ways to use comments in PHP. They are single-line comments and multi-
line comments.
Single-line comments can be used using the conventional ‘#’ sign.
Example:
<?php
# This is a comment
echo "Single-line comment";
?>
Multi-line comments can be denoted using ‘/* */’ in PHP.

36) What are the different types of PHP errors?


There are three main types of errors in PHP. They are as follows:
 Notice: A notice is a non-critical error that is not displayed to the user.
 Warning: A warning is an error that is displayed to the user while the script is
running.
 Fatal error: This is the most critical type of error. A fatal error will cause
immediate termination of the script.
37) Differentiate between GET and POST methods in PHP.
GET Method POST Method
The GET method can only send a maximum There is no restriction on the data size
of 1024 characters simultaneously
GET does not support sending binary data POST supports binary data as well as ASCII
QUERY_STRING env variable is used to The HTTP protocol and the header are used
access the data that is sent to push the data
The $_GET associative array is used to access The $_POST associative array is used to
the sent information access the sent information here
38) What are the steps to create a new database using MySQL and PHP?
There are four basic steps that are used to create a new MySQL database in PHP. They are
as follows:
 First, a connection is established to the MySQL server using the PHP script.
 Second, the connection is validated. If the connection is successful, then you can
write a sample query to verify.
 Queries that create the database are input and later stored into a string variable.
 Then, the created queries are executed one after the other.
39) What is the difference between static and dynamic websites?
Static Websites Dynamic Websites
In dynamic websites, content of script can
In static websites, content can’t be changed
be changed at the run time. Its content is
after running the script. You cannot change
regenerated every time a user visits or
anything in the site as it is predefined.
reloads.

40) What is NULL?

NULL is a special data type which can have only one value. A variable of data type
NULL is a variable that has no value assigned to it. It can be assigned as follows:

$var
1 = NULL;
41) What is MySQL?
Answer: MySQL is an open-source DBMS which is developed and distributed by Oracle
Corporation.
It is supported by most of the popular operating systems, such as Windows, Linux, etc. It
can be used to develop different types of applications but it is mainly used for developing
web applications.

42) What are the features of MySQL?


Some important features of MySQL are mentioned below:
 It is reliable and easy to use too.
 It is a suitable database software for both large and small applications.
 Anyone can install and use it at no cost.
 It is supported by many well-known programming languages, such as PHP, Java,
C++, PERL, etc.
 It supports standard SQL (Structured Query Language).
 The open-source license of MySQL is customizable. Hence, a developer can
modify it according to the requirements of the application.

43) What is the purpose of using the TIMESTAMP data type?


Answer: A TIMESTAMP data type is used to store the combination of date and time
value which is 19 characters long.
The format of TIMESTAMP is YYYY-MM-DD HH:MM: SS. It can store data from
‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC. By default, the current date
and time of the server get inserted in the field of this data type when a new record is
inserted or updated.

44) What are the essential code required for establishing a connection with a MySQL
database using PHP?

The code snippets required for establishing a connection with a MySQL database using
PHP are as follows:

$host = “localhost”;
$username = “root”;
$password = “”;
$database = “test”;

$conn = mysqli_connect($host, $username, $password, $database);

if (!$conn) {
die(“Connection failed: ” . mysqli_connect_error());
}

echo “Connected successfully”;


mysqli_close($conn);
?>
45) What are the differences between MySQL and SQL?
SQL stands for Standard Query Language. It is used to interface with databases such as
MySQL.

MySQL is a database that stores and protects numerous sorts of data. A PHP script is
necessary to store and retrieve values from the database.

SQL is a programming language, but MySQL is a database.

SQL is used to create database management systems, whereas MySQL allows data
handling, storage, deletion, and modification.

446)How can we create a database using PHP and MySQL?

We can create MySQL database with the use of


Mysql_ create_ db(“Database Name”)

You might also like