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
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”)
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
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
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:
- Mysqli_connect( ) Function
- Mysqli_close( ) Function
- mysqli_select_db( ) Function
- mysqli_affected_rows( ) Function
- mysqli_connect_error( ) Function
- mysqlifetchassoc( ) Function
Question 2.
What is MySQLi function?
Answer:
MySQLi functions:
- The Mysqli functions allows you to access MySQL database servers.
- 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:
Types of MySQL Functions in PHP:
- Database connections
- Managing Database connections
- Performing Queries
- Closing connection
Question 4.
Difference between Connection and Close function?
Answer:
Connection:
- Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_ connect( ) Function.
- This function requires 4 parameters.
Close function:
- mysqli close( ) Function is used to close an existing opened database connection between PHP scripting and MySQL Database Server.
- 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).
Question 6.
What is Connection string?
Answer:
The variables are used to connect to the Database server. They are
- $servername → Database Server IP address
- $usemame → Database Server User Name
- $password → Database Server Password
- $DB_Name → 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.
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:
mysqli_fetch_assoc( );
Fetches a result row as an associative array.
Syntax:
mysqli_fetch_assoc(result);
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:
my sql i_affected_rows( ):
mysqli_affected_rows( ) returns the number of affected rows in the previous MYSQL operation.
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”)
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.
The MySQLi extension contains the following important functions which are related to MySQL database connectivity and management.
- Mysqli_connect( ) Function
- Mysqli_close( ) Function
- mysqli_select_db( ) Function
- mysqli_affected_rows( ) Function
- mysqli_connect_error( ) Function
- mysqli_fetch_assoc( ) Function
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_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:
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 about 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 extension in PHP scripting language which gives access to the MYSQL database. MySQLi extension was introduced version 5.0.0.
The MySQLi extension contains the following important functions which are related to MySQL database connectivity and management.
- Mysqli_connect( ) Function
- Mysqli_close( ) Function
- mysqli_select_db( ) Function
- mysqli_affected_rows( ) Function
- mysqli_connect_error( ) Function
- 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 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.
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
- $servemame → Database Server IP address
- $usemame → Database Server User Name
- $password → Database Server Password
- $DB_Name → 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.
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
- $servemame → Database Server Server IP address
- $username → Database Server User Name
- $password → Database Server Password
- $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.
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>’;
Samacheer Kalvi 12th Computer Applications Solutions Connecting PHP and MYSQL Additional Question and Answer
I. Choose The Best Answer
Question 1.
The combination of PHP and MYSQL has become very popular …………………………. web scripting language in internet.
Answer:
Server side
Question 2.
According to recent Survey, approximately ………………………….. websites are running using PHP.
Answer:
544 million
Question 3.
Which is used to convert PHP code into C++?
(a) LPLP
(b) HPHP
(c) BPBP
(d) APAP
Answer:
(b) HPHP
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
Question 5.
Which of the following has written alternative version of PHP?
(a) Facebook
(b) Twitter
(c) Instagram
(d) Whatsapp
Answer:
(a) Facebook
Question 6.
RAD meAnswer: ………………………..
(a) Rigid Application Design
(b) Rapid Application Development
(c) Rare App Design
(d) Raster Audio Development
Answer:
(b) Rapid Application Development
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
Question 9.
Which is an open-source relational database management system?
(a) MySQL
(b) Foxpro
(c) MS-Access
(d) Excel
Answer:
(a) 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.
Mention Some RDBMS Softwares?
Answer:
Relational Database Management System (RDMS) softwares are MySQL, Oracle, IBM DB2, and Microsoft SQLSERVER etc.
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 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.
III. Explain in Brief Answer
Question 1.
Write a Snippet code to check database connection?
Answer:
// Check connection
if(!$conn){
die(“Connection failed: “ . mysqli_connect_error( ));
}
echo “Connected successfully”;
?>
Question 2.
Name the parameters of connect functions?
Answer:
- $servemame → Database Server Server IP address
- $username → Database Server User Name
- $password → Database Server Password
- $DBName → Database Name
Question 3.
Write any 3 special features of PHP?
Answer:
- PHP can embed easily with HTML and client side scripting language
- PHP has built-in function which is easily connect to MySQL database
- PHP scripting language has been supported by many Software frameworks
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.