Tamil Solution

Educational News | Recruitment News | Tamil Articles

Padasalai Co 12th New Study Materials

Padasalai Co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

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

Padasalai.co 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”)

Padasalai.co 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

Padasalai.co 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

Padasalai.co 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:

Mysqli_connect() Function
Mysqli_close() Function
mysqli_select_db() Function
mysqli_afFected_rows() Function
mysqli_connect_error() Function
mysqli_fetch_assoc() Function
Padasalai.co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

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

The Mysqli functions allow 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:

Mysqli_connect() Function
Mysqli_close() Function
mysqli_select_db() Function
mysqli_affected_rows() Function
mysqli_connect_error() Function
mysqli_fetch_assoc() Function
Padasalai.co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

Question 4.
Difference between the 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).

Padasalai.co 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.
Padasalai.co 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);

Padasalai.co 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”)

Padasalai.co 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.
Padasalai.co 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.

Mysqli_connect( ) Function
Mysqli_close( ) Function
mysqli_select_db( ) Function
mysqli_affected_rows( ) Function
mysqli_connect_error( ) Function
mysqli_fetch_assoc( ) Function
Padasalai.co 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);

Padasalai.co 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.
Padasalai.co 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.

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 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);

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

Padasalai.co 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.
,
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 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.

Padasalai.co 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.

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.

Padasalai.co 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 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); Padasalai.co 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 on the internet. Answer: Server-side Question 2. According to a recent survey, approximately ………………………….. websites are running using PHP. Answer: 544 million Padasalai.co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL 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 Padasalai.co 12th Computer Applications Solutions 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 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 Padasalai.co 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 Padasalai.co 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 Padasalai.co 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. Mention Some RDBMS Softwares? Answer: Relational Database Management System (RDMS) softwares are MySQL, Oracle, IBM DB2, and Microsoft SQLSERVER etc. Padasalai.co 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 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”; ?>

Padasalai.co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

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
Padasalai.co 12th Computer Applications Solutions Chapter 9 Connecting PHP and MYSQL

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

PHP can embed easily with HTML and client-side scripting language
PHP has a built-in function that is easily connected to the 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.