Monday, October 31, 2016

php-page3

16. How to print current date and time.

Ans:
<?php echo date('Y-m-d H:i:s'); ?>

17. How to select a database?

Ans:
mysql_select_db($db_name);

18. How can we connect to a MySQL database from a PHP script?

Ans:
To be able to connect to a MySQL database, we must use mysql_connect() function as follows:
<!--?php $database = mysql_connect("HOST", "USER_NAME", "PASSWORD"); mysql_select_db("DATABASE_NAME",$database);

19. How send email using php?

Ans:
To send email using PHP, you use the mail() function.This mail() function accepts 5 parameters as follows (the last 2 are optional). You need webserver, you can't send email from localhost.
eg :
mail($to,$subject,$message,$headers);

20. Explain how to submit form without a submit button.

Ans:
We can achieve the above task by using JavaScript code linked to an event trigger of any form field and call the document.form.submit() function in JavaScript code.



21. How can we increase the execution time of a PHP script?

Ans:
By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.

22. Explain the purpose of output buffering in PHP.

Ans:
Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.

23. What are the encryption techniques in PHP

Ans:
MD5 :  PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg);

mcrypt_encrypt : string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] );
Encrypts plaintext with given parameters

24. Why PHP is also called as Scripting language?

Ans:
PHP is basically a general purpose language, which is used to write scripts. Scripts are normal computer files that consist of instructions written in PHP language. It tells the computer to execute the file and print the output on the screen. PHP is used for webpages and to create websites, thus included as scripting language.

25. What are the steps involved to run PHP?

Ans:
The steps which are involved and required to run PHP is as follows:

1) Set up the web environment.
2) Set up the web servers. There are many web servers that are available and the mostly used is Apaches which automatically remains installed with linux distribution and on windows it is easy to install. There are other servers like IIS (Internet information server) provided by Microsoft can be used to set up the web environment.
3) Install the web server and PHP
4) Update and administer the system for changes.



<Back  I  Sample php programs Next>


EmoticonEmoticon