Ad
Saturday, December 9, 2023
Chapter 4 Files and Database handling
- What is a DSN?
DSN stands for Data Source Name. It is a string that specifies a database connection, typically used in database-related operations.
-How to delete file in PHP?
The unlink() function is used to delete a file in PHP. For example:
$fileToDelete = 'example.txt';
unlink($fileToDelete);
-Write a PHP script accept and insert records in employee table.
<?php
// Assuming database connection is established
$employeeName = $_POST['employeeName'];
$employeeAge = $_POST['employeeAge'];
$employeeSalary = $_POST['employeeSalary'];
$sql = "INSERT INTO employee (name, age, salary) VALUES ('$employeeName', $employeeAge, $employeeSalary)";
// Execute the SQL query to insert records
mysqli_query($conn, $sql);
// Close the database connection
mysqli_close($conn);
?>
-What are the different placeholders used in SQL query?
? (Question Mark):
Used as a parameter placeholder in prepared statements.
:name (Colon Name):
Named placeholders in prepared statements, commonly used in PDO.
$1, $2, ... (Dollar Sign):
Parameter placeholders in PostgreSQL.
- Write steps to create connection with Postgre SQL database and display
the data.
Install PostgreSQL Extension:
Ensure that the PostgreSQL extension is installed and enabled in PHP.
Create Database Connection:
Use pg_connect or PDO to establish a connection to the PostgreSQL database.
Execute Queries:
Use pg_query or other relevant functions to execute SQL queries.
-Consider the following relational data base
Movie (Movie - no , Movie - name, year)
Actor (Actor - no, Actor - name, Movie - no)
<?php
// Assuming database connection is established
$movieName = $_POST['movieName'];
$sql = "SELECT Actor_name FROM Actor WHERE Movie_name = '$movieName'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo $row['Actor_name'] . "<br>";
}
// Close the database connection
mysqli_close($conn);
?>
-State the advantage of using PEAR DB functions.
The PEAR DB library provides a database abstraction layer, making it easier to switch between different database systems without changing the code. It promotes portability and helps in maintaining a consistent interface for database operations.
-Consider a table student (rno, name, class). Assume database
stud already exists. Write a PHP script to accept a student
roll no. and display details of that student using PEAR DB
functions.
<?php
// Assuming database connection is established using PEAR DB
$rollNo = $_POST['rollNo'];
// Execute a query to fetch student details based on roll number
// Use PEAR DB functions like db_query, etc.
// Display student details
echo "Student Roll No: $rollNo";
// Display other details fetched from the database
?>
-Explain prepare ( ) and execute ( ) command in database handling
In PHP database handling with PDO, prepare() is used to prepare an SQL statement, and execute() is used to execute that prepared statement.
-Accept directory name from user. Write PHP program to change current
directory to accepted directory name and count number of files and directories in it
$dir = "/path/to/directory";
chdir($dir);
$files = scandir($dir);
$numFiles = count($files) - 2; // Subtracting . and .. from the count
echo "Number of files and directories: $numFiles";
-Write a PHP script to accept a file name from user and
display last access date and time of a file.
<?php
$filename = 'example.txt';
// Display last access date and time
echo "Last access time: " . date("F d Y H:i:s.", fileatime($filename));
?>
- State the pear db function to get system error message, if
the database connection fails.
-How to get the user ID of the owner of the specified
file ?
-Assume database empdb is already exists. Write a PHP script
using postgreSQL to increment salary of all employees by 10%.
- Consider table emp(eno, ename, salary).
-Write a PHP script to display date and time of a file when
it was last accessed.
-Explain DB :: connect( )
- Which operator is used to compare data as well as data type ?
-What is purpose of file)?
- Write connect function in PEAR DB for pestgreSQL How to release connection in database specifir way?
- Write stope to seept database using database specific way.
-Write a PHP program to add aasigronment record of the given student. Consider-heo, name, assignment, set, question eo, marks, date accept from student).
-What is Data type List different Data types in PHP? Explain
-What are the different class methods and object methods available in PRAR DB ibrary? Kaplain.
- Write purpose of resource data type with suitable example.
About Abhishek Dhamdhere
Qna Library Is a Free Online Library of questions and answers where we want to provide all the solutions to problems that students are facing in their studies. Right now we are serving students from maharashtra state board by providing notes or exercise solutions for various academic subjects
No comments:
Post a Comment