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

Students can Download Computer Applications Chapter 9 Connecting PHP and MYSQL Questions and Answers, Notes Pdf, Samacheer Kalvi 12th Computer Applications Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.

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

Samacheer Kalvi 12th Computer Applications Connecting PHP and MYSQL Text Book Back Questions and Answers

PART – I
I. Choose The Correct Answer

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

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

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

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:
(a) mysqli_close(“Connection Object”)

Samacheer Kalvi 12th Computer Applications Solutions 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”,“Password”,“DB Name”);
(c) mysql_connect(“Server Name”,“User Name”,“Password”,“DB Name”);
(d) mysqli connect (“Database Object”);
Answer:
(a) mysqli_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

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

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 Solutions 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 functions?
(a) Version 2.0
(b) Version 3.0
(c) Version 4.0
(d) Version 5.0
Answer:
(d) Version 5.0

PART – II
II. Short Answer

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. mysqli_fetch_assoc() Function

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

Question 2.
What is MySQLi function?
Answer:
MySQLi functions:

  1. The Mysqli functions allow you to access MySQL database servers.
  2. For the MySQL functions to be available, you must compile PHP with support for the MySQLi extension.

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

  • Mysqli_connect() Function
  • Mysqli_close() Function
  • mysqli_select_db() Function
  • mysqli_affected_rows() Function
  • mysqli_connect_error() Function
  • mysqli_fetch_assoc() Function

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

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

  1. Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_ connect( ) Function.
  2. This function requires 4 parameters.

Close function:

  1. mysqli close( ) Function is used to close an existing opened database connection between PHP scripting and MySQL Database Server.
  2. This function requires only one parameter.

Question 5.
Give few examples of MySQLi Queries?
Answer:
$sql=“SELECT student_name,student_age FROM student”;mysqli_query($con,$sql); sql stmt = “SELECT * FROM my contacts”;
$result = mysqli_query($connection,$sql_stmt).

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

Question 6.
What is the Connection string?
Answer:

  • A connection string Is a string that specifies information about a data source and the means of connecting to it.
  • It is passed in code to an underlying driver or provider in order to initiate the connection.

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

Question 7.
What is web Database?
Answer:
Web Database:
A web database is a wide term for managing data online. A web database gives you the ability to build your own databases.
Ex. Bank, airline and rental car reservation.

Question 8.
What is mysqli_fetch_assoc( ) Function?
Answer:
The mysqli_fetch_assoc() function fetches a result row as an associative array.

Syntax
mysqli_fetch_assoc(result);

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

Question 9.
Define mysqli_connect_error( ) Function?
Answer:
mysqli connect_error( ):
It returns the error description from the last connection error.
Syntax:
mysqli_connect_ertror( ):

Question 10.
Define mysqii_affected_rows( ) Function?
Answer:
The mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query.

Syntax
mysqli_affected_rows(connection);

PART – III
III. Explain in Brief Answer

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

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

Question 2.
Write is the purpose of MySQLi function available?
Answer:
MySQL Function in PHP
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.
Samacheer Kalvi 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL
The MySQLi extension contains the following important functions which are related to MySQL database connectivity and management.

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

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

Question 3.
Differentiate mysqli_affected_rows( ) Function and mysqli_fetch_assoc( ) Function?
Answer:
Fetch assoc( )
mysqli_fetch_assoc( ):
Fetches a result row as an associative array.

Syntax:
mysqli fetch_assoc(result)

Affected rows( )
my sqli_affected_ro ws( ):
mysqli affected_rows( ) returns the number of affected rows in the previous MYSQL operation.

Syntax:
mysqli_affected_rows(connection)

Question 4.
Write MySQL Connection Syntax with example?
Answer:
Syntax:
mysqli_connect(“ServerName”,”UserName”,”- Password”,”DB Name”);

Example:
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);

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

Question 5.
Write a note PHP MySQL database connection?
Answer:
Database Connections:
Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_connect() Function.

Syntax:
mysqli_connect(“Server Name”, “User Name”,“Password”,“DB Name”);
This function requires four parameters to connect to database server. Database Server name, Database username, password and Database Name.

Managing Database Connections:
The below code snippet describes managing database connection methods and features. c?php
$servername = “localhost”;
$username = “username”;
$password = “password”;
$DBname = “SchoolDB”;
// Create connection
$conn = mysqli_connect($servemame, Susername, Spassword,$DB_name).

PART – IV
IV. Explain in detail

Question 1.
Discuss in detail MySQL functions with example?
Answer:
MySQL Function in PHP:
In PHP Scripting language many functions are available for MySQL Database connectivity and executing SQL queries. MySQLi is an extension in PHP scripting language which gives access to the MYSQL database. MySQLi extension was introduced in version 5.0.0.
Samacheer Kalvi 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL
The MySQLi extension contains the following important functions which are related to MySQL database connectivity and management.

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

1. Database Connections:
Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_connect() Function.
Syntax:
mysqli_connect(“Server Name”,“User Name”,“Password”,“DB Name”);
This function requires four parameters to connect to database server. Database Server name, Database username, password and Database Name.

2. Managing Database Connections:
The below code snippet describes managing database connection methods and features.
<?php
$servemame = “localhost”;
$usemame = “username”;
$password = “password”;
$DB_name = “School_DB”;
// Create connection
$conn = mysqli_connect($servemame, Susemame, $password,$DB_name);
The mysqli connect function uses these variables and connect Database server from PHP scripting. If connection gets fail, output will be printed with MySQL error code. Otherwise connection is success.

3. Performing Queries:
The main goal of MySQL and PHP connectivity is to retrieve and manipulate the data from the MySQL database server. The SQL query statements are helping with PHP MySQL extension to achieve the objective of MySQL and PHP connection, “mysqliquery” 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);

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

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

Question 2.
Explain the Database error handling and management process in PHP?
Answer:
Managing Database Connections:
The below code snippet describes managing database connection methods and features.
<?php
$servemame = “localhost”;
$username = “username”;
$password = “password”;
$DBname = “SchoolDB”;
// Create connection
Sconn = mysqli_connect($servemame, Susername, Spassword,SDBname);
// Check connection
if (! Sconn) {
die(“Ccnnection failed: “ . mysqli_connect_error( ));
}.
echo “Connected successfully”;
?>,
In the above code snippet, three variables are used to connect to the database server. They are

  1. $servemame → 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 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.

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

Question 3.
Explain in details types of MySQL connection method in PHP?
Answer:
Database Connections:
Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_connect( ) Function.

Syntax:
mysqli_connect(“Server Name”,“User Name”,“Password”,“DB Name”);
This function requires four parameters to connect to database server. Database Server name, Database username, password and Database Name.

Managing Database Connections:
The below code snippet describes managing database connection methods and features.
<?php
$servemame = “localhost”;
$usemame = “username”;
$password = “password”;
SDB_name = “SchoolDB”;
// Create connection
$conn = mysqli_connect($servemame, Susemame, Spassword,$DB_name);
// Check connection
if(!$conn){
die(“Connection failed: “ . mysqli_connect_error( ));
}
echo “Connected successfully”;
?>
In the above code snippet, three variables are used to connect to the Database server. They are

  1. $servemame → Database Server Server IP address
  2. $username → Database Server User Name
  3. $password → Database Server Password
  4. $DBName → Database Name

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

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

Question 4.
Explain MySQLi Queries with examples?
Answer:

Definition and Usage
The mysqli_query() function performs a query against the database.
The mysqli_query function is used to execute SQL queries.
The function can be used to execute the follow¬ing query types;

  • Insert
  • Select
  • Update
  • delete

Syntax

<?php
mysqli_query($dbhandle,$query);
?>
HERE,

  • “mysqli_query(…)” is the function that executes the SQL queries.
  • “$query” is the SQL query to be executed
  • “$link_identifier” is optional, it can be used to pass in the server connection link

Example:

  • $con = mysqli_connect(“localhost”,”my_ user”,”my_password”,”Student_DB “);
  • $sql=”SELECT student_name,student_age FROM student”;mysqli_query($con,$sql);

Samacheer Kalvi 12th Computer Applications Solutions Connecting PHP and MYSQL Additional Question and Answer

I. Choose The Best Answer

Question 1.
…………… is important to all computer and Internet related applications.
a) Data
b) MySQL
c) PHP
d) None of these
Answer:
a) Data

Question 2.
According to a recent survey, approximately ………………………….. websites are running using PHP.
Answer:
544 million

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

Question 3.
Connection to the Database Server machine via PHP scripting language using ………….Function.
a) mysqli_affected_rows()
b) mysqli_connect_error()
c) mysqli_fetch_assoc()
d) mysqli_connect()
Answer:
d) mysqli_connect()

Question 4.
Expand HPHP:
(a) W\gh Power High Power
(b) Heavy Processor Heavy Processor
(c) Hip Hop
(d) High Hop
Answer:
(c) Hip Hop

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

Question 5.
…………….. Function is used to close an existing opened database connection between PHP scripting and MySQL Database Server.
a) mysqli_close()
b) mysqli_connect_error()
c) mysqli_query()
d) mysqli_connect()
Answer:
b) mysqli_connect_error()

Question 6.
RAD means ………………………..
(a) Rigid Application Design
(b) Rapid Application Development
(c) Rare App Design
(d) Raster Audio Development
Answer:
(b) Rapid Application Development

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

Question 7.
………………………….. is a server-side scripting language designed for web development.
Answer:
PHP

Question 8.
Which is a request for data or ‘information’ from a database table?
(a) row
(b) record
(c) query
(d) report
Answer:
(c) query

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

Question 9.
Which is an open-source relational database management system?
(a) MySQL
(b) Foxpro
(c) MS-Access
(d) Excel
Answer:
(a) MySQL

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

Question 10.
Pick the odd one out.
(a) PRADO
(b) Cake
(c) cake PHP
(d) Symphony
Answer:
(b) Cake

II. Short Answer

Question 1.
Expand RDBMS.
Answer:
Relational Database Management System

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

Question 2.
What is the main goal of providing connectivity between MySql and PHP?
Answer:
The main goal of MySQL and PHP connectivity is to retrieve and manipulate the data from the MySQL database server.

  1. The SQL query statements are helping with PHP MySQL extension to achieve the objective of MySQL and PHP connection.
  2. “mysqli_query” is a function, helps to execute the SQL query statements in PHP scripting – language.

III. Explain in Brief Answer

Question 1.
What Is the main goal of MySQL and PHP connectivity?
Answer:
The main goal of MySQL and PHP connectivity is to retrieve and manipulate the data from the MySQL database server.

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

Question 2.
Name the parameters of connecting functions?
Answer:

  1. $servemame → Database Server Server IP address
  2. $username → Database Server User Name
  3. $password → Database Server Password
  4. $DBName → Database Name

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

Question 3.
Write a short note on the parameters of the mysqSLconnect() function.
Answer:
Four Parameters are used to connect to the Database server.
They are

  • $servername -> Database Server Server IP address
  • $username -> Database Server User Name
  • $password -> Database Server Password
  • $DB_Name -> Database Name

Question 4.
Mention some web frameworks design structures to promote rapid application development (RAD)?
Answer:
Some of these include PRADO, CakePHP, Symfony, Codeigniter, Laravel, Yii Framework, Phalcon, and Zend Framework, offering features similar to other web frameworks.