php question


12) What’s the difference between COPY OF A FILE & MOVE_UPLOAD_FILE in file uploading?
Move: This function checks to ensure that the file designated by filename is a valid upload file (meaning that it
was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename
given by destination.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
Copy: Makes a copy of a file. Returns TRUE if the copy succeeded, FALSE otherwise.
13) How do you insert single & double quotes in MySQL db without using PHP?
& / &quote;
Alternately, escape single quote using forward slash \’ . In double quote you don’t need to escape quotes.
Insert double quotes as “”.
14) What do you need to do to improve the performance (speedy execution) for the script you have written?
If your script is to retrieve data from Database, you should use “Limit” syntax. Break down the non dynamic
sections of website which need not be repeated over a period of time as include files.
15) How do you capture audio/video in PHP?
You need a module installed – FFMPEG. FFmpeg is a complete solution to record, convert and stream audio
and video. It includes libavcodec, the leading audio/video codec library. FFmpeg is developed under Linux,
but it can be compiled under most operating systems, including Windows.
Page 3/8
PDF generated by PHPKB Knowledge Base Script
16) How do you know (status) whether the recipient of your mail had opened the mail i.e. read the mail?
Embed an URL in a say 0-byte image tag may be the better way to go. In other word, you embed an invisible
image on you html email and when the src URL is being rendered by the server, you can track whether your
recipients have view the emails or not.
17) What is random number?
A random number is a number generated by a process, whose outcome is unpredictable, and which cannot
be sub sequentially reliably reproduced.
18) What is difference between srand & shuffle?
The srand function seeds the random number generator with seed and shuffle is used for shuffling the array
values.
shuffle – This function shuffles (randomizes the order of the elements in) an array. This function assigns new
keys for the elements in array. It will remove any existing keys you may have assigned, rather than just
reordering the keys.
srand – Seed the random number generator
19) How can we remove duplicate values from an array?
array_unique() funciton can be used for the purpose.
20) How do I find out weather a number is odd or even?
if (number%2==0 ) then even else odd.
21) How can we get the ID generated from the previous insert operation?
SELECT MAX(ID) from tablename;
22) How to limit the number of rows to 5 that I get out of my database?
Select * from tablename LIMIT 0, 5;
23) How to store binary data in MySQL?
Use BLOB data type for the database field.
24) How can we submit a form without a submit button?
We can submit a form using the JavaScript. Example: document.formname.submit();
25) How can I maintain the count of how many persons have hit my site?
26) What is difference between mysql_fetch_array(), mysql_fetch_row() and mysql_fetch_object()?
mysql_fetch_array – Fetch the all matching records of results.
mysql_fetch_object – Fetch the first single matching record of results.
Page 4/8
PDF generated by PHPKB Knowledge Base Script
mysql_fetch_row – fetches a result row as array.
27) How to make a download page in own site, where I can know that how many file has been loaded by
particular user or particular IP address?
We can log the IP addresses in one database table while downloading the file. This way we can count and
check the no. of rows inserted for a particular download.
28) What is difference between mysql_connect and mysql_pconnect?
mysql_connect opens up a database connection every time a page is loaded. mysql_pconnect opens up a
connection, and keeps it open across multiple requests.
mysql_pconnect uses less resources, because it does not need to establish a database connection every
time a page is loaded.
29) What is the difference between “Insert”, “Update” and “Modify” events?
INSERT – Add a new record into the database table.
MODIFY – If record is available it modifies otherwise it wont modify.
UPDATE – If record is available it updates the record otherwise it creates a new record.
30) How I can get IP address?
getenv(“REMOTE_ADDR”);
31) How to make a login page where once the user has logged in will go back to the page it came from to
login page?
32) How do we know properties of the browser?
You can gather a lot of information about a person’s computer by using $_SERVER[‘HTTP_USER_AGENT’].
This can tell us more about the user’s operating system, as well as their browser. For example I am revealed
to be Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
when visiting a PHP page.
This can be useful to programmers if they are using special features that may not work for everyone, or if
they want to get an idea of their target audience. This also is important when using the get_browser() function
for finding out more information about the browser’s capabilities. By having this information the user can be
directed to a version of your site best suited to their browser.
get_browser() attempts to determine the capabilities of the user’s browser. This is done by looking up the
browser’s information in the browscap.ini file.
echo $_SERVER[‘HTTP_USER_AGENT’] . “


\n”;
$browser = get_browser();
foreach ($browser as $name => $value)
{
echo “$name $value
\n”;
Page 5/8
PDF generated by PHPKB Knowledge Base Script
}
33) What is difference between require_once(), require(), include(). Because all these function are used 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().
34) If you have to work with dates in the following format: “Tuesday, February 14, 2006 @ 10:39 am”, how
can you convert them to another format that is easier to use?
The strtotime function can convert a string to a timestamp.
A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database,
and just output them in the format you like.
So let’s say we have $date = “Tuesday, February 14, 2006 @ 10:39 am”;
In order to convert that to a timestamp, we need to get rid of the “@” sign, and we can use the remaining
string as a parameter for the strtotime function.
So we have
$date = str_replace(“@ “,””,$date);
$date = strtotime($date);
Now $date is a timestamp and we can say:
echo date(“d M Y”,$date);
35) What is CAPTCHA?
CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To
prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an
image containing distorted images of a string of numbers and letters. Computers cannot determine what the
numbers and letters are from the image but humans have great pattern recognition abilities and will be able
to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the
image in the validation field, the application can be fairly assured that there is a human client using it.
36) What is the difference between sessions and cookies?
37) What is the difference between $x and $$x ?
Page 6/8
PDF generated by PHPKB Knowledge Base Script
$x is simple variable. $$x is reference variable or infact a variable of variable. A variable variable allows us to
change the name of a variable dynamically.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s