Php Mysql Question and Answers for Interview

What is the difference between PHP4 and PHP5?
PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)
there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

How i can get ip address – REMOTE_ADDR – the IP address of the client
REMOTE_HOST – the host address of the client, if available

What is the difference between echo and print statement? – echo() can take multiple expressions,Print cannot take multiple expressions.
echo has the slight performance advantage because it doesn’t have a return value.
True, echo is a little bit faster.

How we know browser properties -echo $_SERVER[‘HTTP_USER_AGENT’] . “<hr /> “;
$browser = get_browser();
foreach ($browser as $name => $value) {
echo “<b>$name</b> $value <br /> “;
}

How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)

What is difference between require_once(), require(), include(). Becouse above three function usely use to call a file in another file.
Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.
Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING.
There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().

How do I generate a random number from-php?
srand((double)microtime()*1000000);
echo rand(0,100);

How do I set the browser timeout?
set_time_limit(900);
this sets the timeout too 900 seconds / 15 minutes.

How can I do error handling in php?

Is it possible to connect to a ftp server with php?
Yes it is possible, you can use the ftp_connect function. (PHP 3>= 3.0.13, PHP 4 >= 4.0b4)

How do I find out how a user came to my page?
You have the variable $HTTP_REFERER which holds the page that refered to you page, if there are any referer, ie if the user enters your url directly the referer variable will be empty.

How can I add text to an image?
array imagettftext ( resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text )
how to rotate an image using php code?
$move90 = imagerotate($myimage,90);
//$myimage is the reference to the loaded image, eg through imagecreatefromjpeg

How do I find the size of an array? –use Count function
$values = range(“A”,”Z”);
echo count($values);

How do I remove escape characters from data?
$data = “I\’m the king of the castle”;
echo stripslashes($data); //I’m the king of the castle

What are magic quotes?
Magic quotes is a configuration setting within PHP that means that all data containing a single or double quote, or NUL, will automatically be escaped with a backslash before being entered into a database.

How can we encrypt the username and password using PHP?

What is the difference between $message and $$message?
$message is a simple variable whereas $$message is a reference variable.

What are the differences between DROP a table and TRUNCATE a table?

What’s the difference between md5(), crc32() and sha1() crypto on PHP?
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

How to set cookies?
setcookie(’variable’,’value’,’time’)
;

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.