Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Applications Guide Pdf Chapter 9 Connecting PHP and MYSQL Text Book Back Questions and Answers, Notes.

Tamilnadu Samacheer Kalvi 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

12th Computer Applications Guide Connecting PHP and MYSQL Text Book Questions and Answers

Part I

Choose The Correct Answers

Question 1.
Which one of the following statements
instantiates the mysqil class?
a)mysqli = new mysqli()
b) $mysqli = new mysqli()
c) $mysqfl->new.mysq!i()
d) mysqli->new.mysqli()
Answer:
b) $mysqli = new mysqli()

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 2.
Which one is correct way, we can retrieve the data in the result set of MySQL using PHP?
a) mysql_fetch_row.
b) mysql_fetch_array
c) mysql_fetch_object
d) All the above
Answer:
d) All the above

Question 3.
How Can we Create a Database Using PHP and MySQL?
a) mysqli_create_db(“Database Name”)
b) mysqli_create_ db(” Data”)
c) create_db(“Database Name”)
d) create_db(“Data”)
Answer:
a) mysqli_create_db(“Database Name”)

Question 4.
Which is the correct function to execute the SQL queries in PHP ?
a) mysqli_query(“Connection Object’/’SQL Query”)
b) query(“Connection Object”,”SQL Query”)
c) mysql_query(”Connection Object”,”SQL Query”)
d) mysql_query(“SQL Query”)
Answer:
a) mysqli_query(“Connection Object’/’SQL Query”)

Question 5.
Which is the correct function Closing Connection in PHP ?
a) mysqli_close(“Connection Object”);
b) close(“Connection Object”);
c) mysql_close(“Connection Object”);
d) mysqli_close(“Database Object”);
Answer:
c) mysql_close(“Connection Object”);

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 6.
Which is the correct function to establish Connection in PHP ?
a) mysqli_connect(“Server Name “,” ‘User Name “,”- Password “,” DB Name”);
b) connect(“‘Server Name “,” User Name”,”Pass-word”,”DB Name”);
c) mysql_connect(“Server Name “,” User Name “,” Password “,” DB Name”);
d) mysqli_connect (“Database Object'”‘);
Answer:
c) mysql_connect(“Server Name “,” User Name “,” Password “,” DB Name”);

Question 7.
Which is the not a correct MySQL Function in PHP ?
a) Mysqli_connect() Function
b) Mysqli_close() Function
c) mysqli_select_data() Function
d) mysqli_affected_rows() Function
Answer:
c) mysqli_select_data() Function

Question 8.
How many parameter are required for MYSQLi connect function in PHP ?
a) 2
b) 3
c) 4
d) 5
Answer:
c) 4

Question 9.
How many parameter are required for MYSQLI query function in PHP ?
a) 2
b) 3
c) 4
d) 5
Answer:
a) 2

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 10.
How many parameter are required for MYSQLI Close function in PHP ?
a) 1
b) 2
c) 3
d) 5
Answer:
a) 1

Question 11.
Which version of PHP supports MySQLi fuctions?
a) Version 2.0
b) Version 3.0
c) Version 4.0
d) Version 5.0
Answer:
d) Version 5.0

Part II

Short Answers

Question 1.
What are the MySQLi function available PHP?
Answer:

  1. Mysqli_connect( ) Function
  2. Mysqli_close( ) Function
  3. mysqli_select_db( ) Function
  4. mysqli_affected_rows( ) Function
  5. mysqli_connect_error( ) Function
  6. mysqlifetchassoc( ) Function

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 2.
What is the MySQLi function?
Answer:

  • MySQLi is an extension in PHP scripting language which gives access to the MYSQL database.
  • MySQLi extension was Introduced in version 5.0.0.

Question 3.
What are the types MySQLi function available PHP?
Answer:
Types of MySQL Functions in PHP:

  1. Database connections
  2. Managing Database connections
  3. Performing Queries
  4. Closing connection

Question 4.
Difference between the Connection and Close function?
Answer:

Connection function Close function
This function is used to connect the Database Server machine via PHP scripting language This function is used to close an existing opened database connection between PHP scripting and MySQL Database Server.
This function requires four parameters to con­nect to the database server. This function requires only one parameter to connect to the database server.

Question 5.
Give few examples of MySQLi Queries.
Answer:

  • mysqli_query($con “SELECT FROM Persons”);
  • mysqli_query($con,’INSERT INTO Persons
    (FirstName,LastName,Age)      VALUES
    OGIenn’,’Quagmire’,33)”);

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 6.
What is the connection string?
Answer:
The variables are used to connect to the database server. They are

  1. $servername → Database Server IP address
  2. $usemame → Database Server User Name
  3. $password → Database Server Password
  4. $DB_Name → Database Name

The mysqli connect function uses these variables and connect Database server from PHP scripting. If the connection gets fail, output will be printed with MySQL error code. Otherwise, the connection is a success.

Question 7.
What is a web Database?
Answer:

  • A Web database is a database application de¬signed to be managed and accessed through the Internet.
  • In other words, the light databases that support the web applications are also known as Web Databases.

Question 8.
What is mysqli_fetch_assoc() Function?
Answer:
mysqli_fetch_assoc( );
Fetches a result row as an associative array.
Syntax:
mysqli_fetch_assoc(result);

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 9.
Define mysqli_connect_error() Function.
Answer:
The mysqli_connect_error() function returns the error description from the last connection error, if any.

Syntax
mysqli_connect_error();

Question 10.
Define mysqIi_affected_rows() Function.
Answer:
my sqli_affected_rows( ):
mysqli_affected_rows( ) returns the number of affected rows in the previous MYSQL operation.

Syntax:
mysqli_affected_rows(connection)

Part III

Explain in brief answers

Question 1.
Write the Syntax for MySQLi Queries.
Answer:
Syntax:
mysqli_query(“Connection Object”,”SQL Query”)

Parameter Description
connection Required. Specifies the MySQL connection to use
query Required. Specifies the query string
resultmode Optional. A constant. Either: MYSQLI_USE_RESULT (Use this if we have to retrieve large amount of data)
MYSQLI_STORE_RESULT (This is default)

Question 2.
Write is the purpose of MySQLi function available.
Answer:

  • MySQLi is extension in PHP scripting language which gives access to the MYSQL database.
  • The mysqli functions are designed to communicate with MySQL
  • The mysqli_query() function performs a query against the database.

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 3.
Differentiate mysq I i_jaffected_ rows()
Function and mysqli_fetch_assoc() Function.
Answer:

mysqli_affected_ rows() mysqli_fetch_assoc()
It returns the number of affected rows in the pre­vious SELECT, INSERT, UPDATE, REPLACE, or DELETE query. It fetches a result row as an associative ar­ray.
Specifies the MySQL connection to use Specifies a result set identifier returned by mysqli_queryO, mysq-li_store_result()      or mysqli_use_result()
Syntax:
mysqli_affected_rows (connection);
Syntax:
mysqli_fetch_as-soc(result);

Question 4.
Write MySQL Connection Syntax with example.
Answer:
Syntax:
mysqli_eonnect(“Server Name”, “User Name”, “password”, “DB Name”);
Example:
<?php
Sservername = “localhost”;
Susername = “username”;
Spassword = “password”;
$DB_name = “SchooLDB”;
// Create connection
$conn = mysqli_connect($servemame, Susername, Spassword,$DB_name);

Question 5.
Write a note PHP MySQL database connection.
Answer:

  • The combination of PHP and MySQL has become very popular server-side web scripting language in the Internet.
  • MySQL and PHP scripting language connectivity, which covers Database connection establishment, Database Selection, SQL statement execution, and Connection termination.

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Part IV

Explain in detail

Question 1.
Discuss in detail MySQL functions for example.
Answer:

  • In PHP Scripting language many functions are available for MySQL Database connectivity and executing SQL queries.
  • MySQLi is extension in PHP scripting language which gives access to the MYSQL database.
  • MySQLi extension was introduced version 5.0.0.
  • Some of the MySQL functions are following
  • MySQL COUNT Function The MySQL COUNT aggregate function is used to count the number of rows in a database table.
    Example: mysql>SELECT COUNT(*) FROM employee_tbl;
  • MySQL MAX Function The MySQL MAX aggregate function allows us to select the highest (maximum) value for a certain column.
    Example: mysql > SELECT MAX(daily_typing_ pages)-> FROM employee_tbl;
  • MySQL MIN Function The MySQL MIN aggregate . function allows us to select the lowest (minimum)
    value for a certain column.
    Example: MySQL > SELECT MIN(daily_typing_ pages)-> FROM employee_tbl;
  • MySQL AVG Function The MySQL AVG aggregate function selects the average value for certain table column.
    Example: MySQL > SELECT AVG(daily_typing_ pages)-> FROM employee_tbl;
  • MySQL SUM Function The MySQL SUM aggregate function allows selecting the total for a numeric column.
    Example: mysql> SELECT SUM(daily_typing_ pages)-> FROM employee_tbl;

Question 2.
Explain the Database error handling and management process in PHP?
Answer:

  • When an error occurs, depending on your config- j □ration settings, PHP displays the error message in the web browser with information relating to the error that occurred.
  • PHP offers a number of ways to handle errors.
  • We are going to look at three commonly used methods;

Die statements;

  • • The die function combines the echo and exit function in one.
  • • It is very useful when we want to output a message and stop the script execution when | an error occurs.

Custom error handlers: These are user-defined functions that are called whenever an error occurs.

PHP error reporting:

  • The error message depending on your PHP error reporting settings.
  • This method is very useful in development: environment when you have no idea what; caused the error.
  • The information displayed can help you debug your application

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 3.
Explain in details types of MySQL connection method in PHP.
Answer:
Open a Connection to MySQL
There are several methods for connecting to a MySQL database using PHP:

  • MySQL Improved (mysqli) extension
  • PDO (PHP Data Objects)
  • Legacy MySQL (mysql_) functions
  • Connecting to a remote MySQL database using PHP

Connecting to MySQL using the MySQL Improved extension
The MySQL Improved extension uses the mysqli class, which replaces the set of legacy MySQL functions.

Connecting to MySQL using PDO (PHP Data Objects)

  • The MySQL Improved extension can only be used with MySQL databases.
  • PDO, on the other hand, abstracts database access and enables you to create code that can handle different types of databases.

Connecting to MySQL using the legacy MySQL functions

  • The original PHP MySQL functions (whose names begin with mysql_) are deprecated in PHP 5.5, and will eventually be removed from PHP.
  • Therefore, you should only use these functions when absolutely necessary for backward compatibility.
  • If possible, use the MySQL Improved extension or PDO instead.

Connecting to a remote MySQL database using PHP

  • The previous examples all assume that the PHP script runs on the same server where the MySQL database is located.
  • But what if you want to use PHP to connect to a MySQL database from a remote location.
  • For example, you may want to connect to your A2 Hosting database from a home computer or from another web server.

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 4.
Explain MySQLi Queries with examples.
Answer:
Performing Queries:
The main goal of MySQL and PHP connectivity is to retrieve and manipulate the data from MySQL database server. The SQL query statements are helping with PHP MySQL extension ^to achieve the objective of MySQL and PHP connection. “mysqli_query” is a function, helps to execute the SQL query statements in PHP scripting language.

Syntax:
mysqli_query(“Connection Object” “SQL Query”)
Example:
$con=mysqli_connect(“localhost”,“my_user”,“my_password”,“Student_DB”); $sql=“SELECT student_name,student_age FROM student”;mysqli_query($con,$sql);

Closing Connection:
mysqli_close( ) Function is used to close an existing opened database connection between. PHP scripting and MySQL Database Server.

Syntax:
mysqli_close(“Connection Object”);
<?php
$con=mysqli_connect(“localhost”,“$user”,“$password”,“SCHOOLDB”);
// ….some PHP code… mysqli_close($con);
?>

Example of PHP and MySQL Program:
<?php .
$servemame = “localhost”;
$usemame = “username”;
$password = “password”;
$dbname = “schoolDB”;
$connection = mysqli_connect(“$servemame”, “$usemame”, “$password” “$dbname”);
if (mysqli_connect_error ( ))
{
echo “Failed to connect to MySQL:”
mysqli_connect_error( );
}
sql stmt = “SELECT * FROM mycontacts”; //SQL select query
$result = mysqli_query($connection,$sql_stmt);//execute SQL statement$rows =
mysqli__num_r°ws($result);// get number of rows returned
if($rows) {
while ($row = mysqli_fetch_array($result)) {
echo ‘ID:’. $row[‘id’]. ‘<br>’;

12th Computer Applications Guide Connecting PHP and MYSQL Additional Important Questions and Answers

Part A

Choose the correct answers:

Question 1.
The combination of PHP and MYSQL has become very popular …………………………. web scripting language on the internet.
Answer:
Server-side

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 2.
Which of the following is not an RDBMS?
a) Oracle
b) IBM DB2
c) Microsoft SQLSERVER
d) None of these
Answer:
d) None of these

Question 3.
Which is used to convert PHP code into C++?
(a) LPLP
(b) HPHP
(c) BPBP
(d) APAP
Answer:
(b) HPHP

Question 4.
…………… is a function, helps to execute the SQL query statements in PHP scripting language.
a) mysqli_close()
b) mysqli_connect_error()
c) mysqli_query()
d) mysqli_connect()
Answer:
c) mysqli_query()

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 5.
Which of the following has written an alternative version of PHP?
(a) Facebook
(b) Twitter
(c) Instagram
(d) Whatsapp
Answer:
(a) Facebook

Fill in the blanks:

1. RDMS stands ……………….
Answer:
Relational Database Management System

2. SQL stands ……………….
Answer:
Structure query language

3. MySQLi extension was introduced version……………….
Answer:
5.0.0

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

4. ……………….is an extension in PHP scripting language which gives access to the MYSQL database.
Answer:
MySQLi

5. Connect function requires ………………. a number of parameters to connect to database server.
Answer:
four

Choose the incorrect statements:

1. a) PHP is an Open source & Community support scripting language
b) PHP is a server-side scripting language designed for Web development.
c) Only twenty Percentage of Website has been built by PHP and MySQL
d) Data is important to all computer and Internet-related applications.
Answer:
c) Only twenty Percentage of Website has been built by PHP and MySQL

2. a) mysqli_connect() function requires two parameters to connect to the database server.
b) Major of the web servers can support PHP scripting language
c) PHP can embed easily with HTML and client-side scripting language
d) PHP has a built-in function which is easily connected to the MySQL database
Answer:
a) mysqli_connect() function requires two parameters to connect to database server.

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

3. a) PHP scripting language has been supported by many Software frameworks
b) MySQLi is extension in HTML.
c) MySQLi gives access to the MYSQL database.
d) MySQLi extension was introduced in version 5.0.0.
Answer:
b) MySQLi is extension in HTML.

4. a) mysqli_connect() function is used to connect to
database server
b) If the connection gets fails, the output will be printed with MySQL error code.
c) If the connection gets true, there is no output to display.
d) The main goal of HTML and PHP connectivity is to retrieve and manipulate the data
Answer:
c) If the connection gets true, there is no output to display.

5. a) The SQL query statements are helping with PHP
MySQL extension
b) mysqli_connect() function, helps to execute the SQL query statements in PHP scripting language
c) MySQL is an open-source relational database management system.
d) mysqli_close() function requires two parameters to close an existing opened database connection
Answer:
d) mysqli_close() function requires two parameters to close an existing opened database connection

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Short Answers

Question 1.
Mention Some RDBMS Softwares?
Answer:
Relational Database Management System (RDMS) softwares are MySQL, Oracle, IBM DB2, and Microsoft SQLSERVER etc.

Question 2.
What is MySQLi?
Answer:
MySQLi is an extension in PHP scripting language which gives access to the MYSQL database.

Question 3.
What are the major operations of the database?
Answer:
INSERT, SELECT, UPDATE and DELETE

Question 4.
How many parameters to connect to the database server in Mysqli_connect() Function?
Answer:
This function requires four parameters to connect to database server

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 5.
What is the mash goal of MySQL and PHP connectivity?
Answer:
To retrieve and manipulate the data from the MySQL database server.

Find the odd one on the following

Question 1.
a) MySQL
b) Java
c) DB2
d) Oracle
Answer:
b) Java

Question 2.
a) TRUNCATE
c) UPDATE
b) SELECT
d) INSERT
Answer:
a) TRUNCATE

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 3.
a) $servername
b) $client name
c) $username
d) $password
Answer:
c) $username

Question 4.
a) Mysqli_connect() Function
b) Mysqli_close() Function
c) Mysqli_create_db() Function
d) Mysqli_select_db() Function
Answer:
c) Mysqli_create_db() Function

Question 5.
a) MysqlLaffected_rows() Function
b) Mysqli_connect_error() Function
c) Mysqli_fetch_assoc() Function
d) Mysqli_delete_db() Function
Answer:
d) Mysqli_delete_db() Function

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Match the following

Question 1.
A) DB2 – 1) Connect database server
B) INSERT – 2) RDBMS
C) Mysqli_close() Function – 3) One of the major operation
D) Mysqli_connect() Function – 4) Close an existing opened database
a) 1 2 3 4
b) 4 3 2 1
c) 2 3 4 1
d) 2 4 3 1
Answer:
c) 2 3 4 1

Question 2.
A) DB2 -1) Open source
B) SQLSERVER – 2) IBM
C) MySQL – 3) Microsoft
D) Oracle – 4) Oracle Corporation
a) 2 3 1 4
b) 4 3 2 1
c) 2 3 4 1
d) 2 4 3 1
Answer:
a) 2 3 1 4

Question 3.
A) Mysqli_close() Function -1) Four parameters
B) Mysqli_connect() Function -2) Two parameters
C) mysqli_queryO Function -3) No parameters
D) mysqli_connect_errno() -4) One Parameter
a) 2 3 1 4
b) 4 3 2 1
c) 2 3 4 1
d) 4 1 2 3
Answer:
d) 4 1 2 3

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 4.
A) Mysqli_close() Function -1) Fetches a result row
B) Mysqli_connect() Function -2) To execute the SQL query
C) mysqli_query() Function -3) To connect to database server
D) mysqli_fetch_assoc() -4) To close an existing opened database
a) 2 3 1 4
b) 4 3 2 1
c) 2 3 4 1
d) 4 1 2 3
Answer:
b) 4 3 2 1

Question 5.
A) mysqli_affected_rows()Returns the number of affected rows
B) mysqli_connect_error() – Returns the error description
C) MySQL MAX Function – Select the highest value for a certain column.
D) MySQL MIN Function- – Select the lowest value for a certain column.
a) 2 3 1 4
b) 1 2 3 4
c) 2 3 4 1
d) 4 1 2 3
Answer:
b) 1 2 3 4

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

SYNTAX:

1. Closing Connection:
mysqli_close(“Connection Object”);

2. Performing Queries
mysqli_query(“Connection Object”,”SQL Query”)

3. Database Connections:
mysqli_connect(“Server Name Password””DB Name”);

Part B

Short Answers

Question 1.
What is MySQL?
Answer:

  • MySQL is the most popular Open Source Relational SQL Database Management System.
  • MySQL is one of the best RDBMS being used for developing various web-based software, applications.

Question 2.
Write a Snippet code to check database connection?
Answer:
// Check connection
if(!$conn){
die(“Connection failed: “ . mysqli_connect_error( ));
}
echo “Connected successfully”;
?>

Question 3.
What is the use of SQL statements in PHP?
Answer:
The SQL query statements are helping with PHP MySQL extension to achieve the objective of MySQL and PHP connection.

Samacheer Kalvi 12th Computer Applications Guide Chapter 9 Connecting PHP and MYSQL

Question 4.
How the connection will get success in the mysqli_connect() function?
Answer:

  • The MySQL connect function uses these variables and connects the Database server from PHP scripting.
  • If the connection gets fail, the output will be printed with MySQL error code. Otherwise, the connection is a success.

Part C

Brief Answers

Question 1.
Write any 3 special features of PHP?
Answer:

  1. PHP can embed easily with HTML and client-side scripting language
  2. PHP has a built-in function that is easily connected to the MySQL database
  3. PHP scripting language has been supported by many Software frameworks