Question:- What is PHP session_start() and session_destroy() function?
Answer:- PHP session_start() function is used to start the session. It starts new or resumes the current session. It returns the current session if the session is created already. If the session is not available, it creates and returns new sessions.
Question:- What is the difference between session and cookie?
Answer:- The main difference between session and cookie is that cookies are stored on users computer in the text file format while sessions are stored on the server side. Cookies cant hold multiple variables, on the other hand, Session can hold multiple variables. You can manually set an expiry for a cookie, while session only remains active as long as browser is open.
Question:- Write syntax to open a file in PHP?
Answer:- PHP fopen() function is used to open file or URL and returns resource. It accepts two arguments: $filename and $mode Syntax: resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
Question:- How to read a file in PHP?
Answer:- PHP provides various functions to read data from the file. Different functions allow you to read all file data, read data line by line, and read data character by character. PHP file read functions are given below: fread(), fgets(), fgetc()
Question:- How to write in a file in PHP?
Answer:- PHP fwrite() and fputs() functions are used to write data into file. To write data into a file, you need to use w, r+, w+, x, x+, c or c+ mode.
Question:- How to delete file in PHP?
Answer:- The unlink() function is used to delete a file in PHP. bool unlink (string $filename)
Question:- What is the method to execute a PHP script from the command line?What is the method to execute a PHP script from the command line?
Answer:- You should just run the PHP command line interface (CLI) and specify the file name of the script to be executed as follows.
Question:- How to upload file in PHP?
Answer:- The move_uploaded_file() function is used to upload file in PHP. bool move_uploaded_file ( string $filename , string $destination )
Question:- How to download file in PHP?
Answer:- How to download file in PHP?
Question:- How can you send email in PHP?
Answer:- The mail() function is used to send email in PHP. bool mail($to,$subject,$message,$header);
Question:- How do you connect MySQL database with PHP?
Answer:- There are two methods to connect MySQL database with PHP. Procedural and object-oriented style.
Question:- How to create connection in PHP?
Answer:- The mysqli_connect() function is used to create a connection in PHP. resource mysqli_connect (server, username, password)
Question:- How to create database connection and query in PHP?
Answer:- Since PHP 4.3, mysql_reate_db() is deprecated. Now you can use the following 2 alternatives. mysqli_query() , PDO::_query()
Question:- How can we increase execution time of a PHP script?
Answer:- By default, the maximum execution time for PHP scripts is set to 30 seconds. If a script takes more than 30 seconds, PHP stops the script and returns an error. You can change the script run time by changing the max_execution_time directive in the php.ini file. When a script is called, set_time_limit function restarts the timeout counter from zero. It means, if default timer is set to 30 sec, and 20 sec is specified in function set_time_limit(), then script will run for 45 seconds. If 0sec is specified in this function, script takes unlimited time.
