Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Friday, August 31, 2007

PHP-MySQL Interview Questions

What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
Who is the father of PHP and explain the changes in PHP versions?
How can we submit a form without a submit button?
In how many ways we can retrieve the date in the result set of mysql using PHP?
What is the difference between mysql_fetch_object and mysql_fetch_array?
What is the difference between $message and $$message?
How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP?
How can we create a database using PHP and mysql?

What are the differences between require and include, include_once?
Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
Functions in IMAP, POP3 AND LDAP?
How can I execute a PHP script using command line?
Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode ?
Shopping cart online validation i.e. how can we configure Paypal, etc.?
What is meant by nl2br()?
Draw the architecture of Zend engine?
What are the current versions of apache, PHP, and mysql?
What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?
How can we encrypt and decrypt a data present in a mysql table using mysql?
How can we encrypt the username and password using PHP?
What are the features and advantages of object-oriented programming?
What are the differences between procedure-oriented languages and object-oriented languages?
What is the use of friend function?
What are the differences between public, private, protected, static, transient, final and volatile?
What are the different types of errors in PHP?
What is the functionality of the function strstr and stristr?
What are the differences between PHP 3 and PHP 4 and PHP 5?
How can we convert asp pages to PHP pages?
What is the functionality of the function htmlentities?
How can we get second of the current time using date function?
How can we convert the time zones using PHP?
What is meant by urlencode and urldocode?
What is the difference between the functions unlink and unset?
How can we register the variables into a session?
How can we get the properties (size, type, width, height) of an image using PHP image functions?
How can we get the browser properties using PHP?
What is the maximum size of a file that can be uploaded using PHP and how can we change this?
How can we increase the execution time of a PHP script?
How can we take a backup of a mysql table and how can we restore it. ?
How can we optimize or increase the speed of a mysql select query?
How many ways can we get the value of current session id?
How can we destroy the session, how can we unset the variable of a session?
How can we destroy the cookie?
How many ways we can pass the variable through the navigation between the pages?
What is the difference between ereg_replace() and eregi_replace()?
What are the different functions in sorting an array?
How can we know the count/number of elements of an array?
What is the PHP predefined variable that tells the What types of images that PHP supports?
How can I know that a variable is a number or not using a JavaScript?
List out some tools through which we can draw E-R diagrams for mysql.
How can I retrieve values from one database server and store them in other database server using PHP?
List out the predefined classes in PHP?
How can I make a script that can be bilanguage (supports English, German)?
What are the difference between abstract class and interface?
How can we send mail using JavaScript?





How can we repair a MySQL table?
What are the advantages of stored procedures, triggers, indexes?
What is the maximum length of a table name, database name, and fieldname in MySQL?
How many values can the SET function of MySQL take?
What are the other commands to know the structure of table using MySQL commands except explain command?

How many tables will create when we create table, what are they?
What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?
What is maximum size of a database in MySQL?
Give the syntax of Grant and Revoke commands?
Explain Normalization concept?
How can we find the number of rows in a table using MySQL?
How can we find the number of rows in a result set using PHP?
How many ways we can we find the current date using MySQL?
What are the advantages and disadvantages of Cascading Style Sheets?
What type of inheritance that PHP supports?
How can increase the performance of MySQL select query?
The structure of table view buyers is as follows:
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+----------------+
| user_pri_id | int(15) | | PRI | NULL | auto_increment |
| userid | varchar(10) | YES | | NULL | |
+----------------+-------------+------+-----+---------+----------------+
the value of user_pri_id the last row 2345 then What will happen in the following conditions?

Condition1: Delete all the rows and insert another row then. What is the starting value for this auto incremented field user_pri_id ,
Condition2: Delete the last row(having the field value 2345) and insert another row then. What is the value for this auto incremented field user_pri_id

What are the advantages/disadvantages of MySQL and PHP?
What is the difference between GROUP BY and ORDER BY in Sql?
What is the difference between char and varchar data types?
What is the functionality of md5 function in PHP?
How can I load data from a text file into a table?
How can we know the number of days between two given dates using MySQL?
How can we know the number of days between two given dates using PHP?
How can we change the name of a column of a table?
How can we change the name and data type of a column of a table?
What are the differences between drop a table and truncate a table?
When you want to show some part of a text displayed on an HTML page in red font color, what different possibilities are there to do this? What are the advantages/disadvantages of these methods?
When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?
What are the different methods of passing data or information between two calls of a web page? What are the advantages/disadvantages of these methods?
An Apache web server is running on a Linux system. Suddenly, the web server delivers the pages very slow. How could you find out possible reasons for that (when using system commands, please specify their names)?
What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag. Example: The regular expression should match the tag and give the URL (”http://www.yoursite.com /”) as a return result. Tags should also be matched if they contain other attributes than the HREF attribute.
A select query over a large table runs very slow because of the growing number of entries in that table. What different measures could be taken to improve speed?
A company wants to store their invoices in a database. They already have their customers and articles in that database. Both customer and article are each identified by an unique integer value. Please create the SQL statements for creating the necessary table(s) for storing the invoices in a MySQL database. An invoice should hold information like invoice number, customer, date, article(s) and quantity etc.
For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number “1234?. The query should be able to run under a MySQL 4.0 database.
How would you backup and restore a big MySQL database? What are the advantages of the approach which you have taken over the others?
Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.
What is MIME?
What is PEAR in PHP?
How can I use the COM components in PHP?
How can I load the DLLs dynamically?
How many ways we can give the output to a browser?
How can we know that a session is started or not?
What is the default session time in PHP and how can I change it?
What changes I have to done in PHP.ini file for file uploading?
What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?
How can I set a cron and how can i execute it in Unix, Linux, and windows?
Steps for the payment gateway processing?
How many ways I can register the variables into session?
Explain different types of errors in PHP (i.e. arguments in errorreporting function)?
How many ways I can redirect a PHP page?
List out different arguments in PHP header function?
What type of headers have to add in the mail function in which file a attached?
What is the difference between
What are the differences between PHP3 and PHP4 versions?
What are the differences between include() and include_once() functions?
Describe the importance of DABA BASE ABSTRACTION LAYERS in PHP and database connection?
Explain MySQL optimization?
What is the difference between using copy() and move() function in PHP file uploading?
What is the difference between Reply-to and Return-path in the headers of a mail function?
Explain about Type Juggling in PHP?
How can I get the only name of the current executing file?
How can I embed a java programme in PHP file and what changes have to be done in PHP.ini file?
How can I find what type of images that the PHP version supports?
The table tbl_sites contains the following data:
-----------------------------------------------------
Userid sitename country
------------------------------------------------------

Monday, August 13, 2007

Tips for a fast loading web site.

It is important to have a reasonably fast loading web site so that viewers are not made to wait for a long time and to accommodate users on slow internet connections. Search engine algorithms also do take into consideration your load time.

Follow these tips while designing and developing your site:

1. Optimize your HTML code: Make sure that your site doesn't have any unwanted tags and that it is optimized.
2. Effective Table designing: Design using nested tables instead of using cell merges and splits. Use separate tables where ever possible. Not designing for 100% height is better as if you use just one outer table, the web page is displayed only after the table is loaded fully. If many outer tables are present [you can have different tables for the header, content, footer, etc.] the page displays the content of each table as soon as its elements are loaded.
3. Maximize content area: This not only reduces load time, it enhances the readability of your site.
4. Minimize use of graphics, Flash, scripts: These are the major contributors to the size of your web page, so try minimizing them. Try using background colors and fills instead of heavy images.
5. Optimize all heavy files: As much as possible optimize heavy graphics, Flash files and scripts. In editors like fireworks and flash you can see the various options in the preview panel to reduce the sizes. See how popular web sites like google and yahoo have pages that are very small in size and thus load in seconds.
6. Stick to simple designs: Most fast loading sites have very simple designs. Take the hint! Complicated designs will slow down your pages.
Spread out your content: In case you find yourself having very long pages of content, break them down into separate sections and thus bring down the sizes of the individual pages.
7. Use Text Links instead of graphic buttons: basically try to make use of HTML as much as possible. Use CSS Styles for text links to make them as attractive as buttons. Read our CSS Styles tutorial
8. Use Server Side Include (SSI) files where ever possible. SSI files once called from the web server reside in its cache so on subsequent requests they load faster.
9. Using Layers instead of tables is a new concept for better load time. We will be bringing out an article on it soon.

Check your Load time

Do remember to check your Load time regularly. Use free site tools available on the internet (example: netmechanic.com) to check your site load time.

Friday, August 10, 2007

Form Validation while Submit

function blogsFormValidations(formNm)
{
form_feilds_mynames = new Array("Topic","First Name"," Last Name","Email Id","Post Fourm");

form_feilds_names = new Array("txtBlogtopic","txtFirstName","txtLastName","txtEmail","textarea");

if(!check(formNm,form_feilds_mynames,form_feilds_names)){
return false;

}else if(formNm.txtBlogtopic.value=="")
{
alert("Cannot Submit!!\n\n Please Insert Topic.\n");
formNm.selSalutation.focus();
return false;

}else if(checkEmail(formNm.txtEmail.value))
{
alert("Please Enter Valid Email.\n");
formNm.txtEmail.focus();
return false;
}else {
formNm.action.value='send_query';
formNm.submit();
}
}


onclick="javascript:blogsFormValidations(document.frmPostBlogs);"

Wednesday, August 1, 2007

Basic MySQL Interview Question Set

1. How can we repair a MySQL table?
The syntex for repairing a mysql table is
REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
This command will repair the table specified
if the quick is given the mysql will do a repair of only the index tree if the extended is given it will create index row by row

2. Maximum lenghth of mnames of database, table, columns
database- 64
table -64
columns-64
alias-255

3. How many values can the SET function of MySQL take?
Mysql set can take zero or more values but at the maximum it can take 64 values

4. What are the other commands to know the structure of table using MySQL commands except explain command?
describe table_name;

5. How can we find the number of rows in a table using MySQL?

Use this for mysql
>SELECT COUNT(*) FROM table_name;
but if u r particular about no of rows with some special result
do this
>SELECT [colms],COUNT(*) FROM table_name [where u put conditions];
and for PHP it cant be more simple
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo ¡°$num_rows rows found¡±;

6. How many ways we can we find the current date using MySQL?
SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()

7. Give the syntax of Grant and Revoke commands?
The generic syntax for grant is as following
> GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY [password]
now rights can be
a) All privilages
b) combination of create, drop, select, insert, update and delete etc.
we can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name
username@hotsname can be either username@localhost, username@hostname and username@%
where hostname is any valid hostname and % represents any name, the *.* any condition
password is simply the password of user
The generic syntax for revoke is as following
> REVOKE [rights] on [database/s] FROM [username@hostname]
now rights can be as explained above
a) All privilages
b) combination of create, drop, select, insert, update and delete etc.
username@hotsname can be either username@localhost, username@hostname and username@%
where hostname is any valid hostname and % represents any name, the *.* any condition

8. The structure of table view buyers is as follows:
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
| Field | Type | Null | Key | Default | Extra |
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
| user_pri_id | int(15) | | PRI | NULL | auto_increment |
| userid | varchar(10) | YES | | NULL | |
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
the value of user_pri_id the last row 2345 then What will happen in the following conditions?
Condition1: Delete all the rows and insert another row then. What is the starting value for this auto incremented field user_pri_id ,
Condition2: Delete the last row(having the field value 2345) and insert another row then. What is the value for this auto incremented field user_pri_id
In botth cases let the value for auto increment field be n then next row will have value n+1 i.e. 2346

9. What is the difference between char and varchar data types?
Set char to occupy n bytes and it will take n bytes even if u r storing avalue of n-m butes
Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes
eg. name char(10) will waste 5 bytes if we store ¡®kumar¡¯, if each char takes a byte
eg. name varchar(10) will just use 5 bytes if we store ¡®kumar¡¯, if each char takes a byte. rest 5 bytes will be free.

10. What is the functionality of md5 function in PHP?
string md5(string)
Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

11. How can I load data from a text file into a table?
The mysql provides a LOAD DATA INFILE syntax. U can load data from a file. Gr8 tool but u need to make sure that
a) data is delimited
b) u match the colms and data correctly
dont use w/out first learning the syntax

12. How can we know the number of days between two given dates using MySQL?
Use DATEDIFF()
>SELECT DATEDIFF(NOW(),¡¯1947-08-15¡ä);
will give u the exact no of days India got independence from British.

13. How can we know the number of days between two given dates using PHP?
Simple arithmetic.
$date1 = date(¡±Y-m-d¡±);
$date2 = ¡°1947-08-15¡å;
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo ¡± No of $days we got independence from Britts¡±;

14. How can we change the name of a column of a table?
How can we change the name and data type of a column of a table?
this will change the name of colm
> ALTER TABLE table_name CHANGE old_colm_name new_colm_name
this will change the name of colm and also the datatype
> ALTER TABLE table_name CHANGE old_colm_name new_colm_name [data type]

15. What are the differences between drop a table and truncate a table?
>DROP TABLE table_name
Will DELETE the table and DATA
>TRUNCATE TABLE table_name
Will DELETE the table DATA not the table definition

16. The structure of table view buyers is as follows:
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
| Field | Type | Null | Key | Default | Extra |
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
| user_pri_id | int(15) | | PRI | NULL | auto_increment |
| userid | varchar(10) | YES | | NULL | |
+¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª-+¡ª¡ª+¡ª¨C+¡ª¡ª¡ª+¡ª¡ª¡ª¡ª¡ª-+
the value of user_pri_id the last row 2345 then What will happen in the following conditions?
Condition1: Delete all the rows and insert another row then. What is the starting value for this auto incremented field user_pri_id ,
Condition2: Delete the last row(having the field value 2345) and insert another row then. What is the value for this auto incremented field user_pri_id
Mr. Kumar has given its answer but if you have used mysql as backend and if you fire a query ¡°delete from tablename¡± then in mysql it will reset auto index. so for condition one it will start from value 1.
for condition 2 it will start from n+1

17. What is PEAR in PHP
PEAR is short for ¡°PHP Extension and Application Repository¡± and is pronounced just like the fruit. The purpose of PEAR is to provide:
A structured library of open-sourced code for PHP users
A system for code distribution and package maintenance
A standard style for code written in PHP
The PHP Foundation Classes (PFC),
The PHP Extension Community Library (PECL),
A web site, mailing lists and download mirrors to support the PHP/PEAR community
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.
http://pear.php.net/manual/en/introduction.php

18. A .66
select count(id) id ,sitename from tbl_sites group by sitename having id>1;
Tech Interviews comment by Nasim Abbas

19. What is the difference between GROUP BY and ORDER BY in Sql?
ORDER BY [col1],[col2],¡­,[coln]; Tels DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.
GROUP BY [col1],[col2],¡­,[coln]; Tels DBMS to group results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average.

21. What is MIME?
MIME is Multipurpose Internet Mail Extensions is an internet standard for the format of e-mail. Howewer browsers also uses MIME standart to transmit files. MIME has a header wich is added to a begining of the data. When browser sees such header it shows the data as it would be a file (for example image)
some mimes:
audio/x-ms-wmp
image/png
aplication/x-shockwave-flash

22. .How can we know that a session is started or not?
a session starts by session_start()function.
this session_start() is always declared in header portion.it always declares first.then we write session_register().

24. What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?
MySQL_fetch_array()->Fetch a result row as an associative array,numeric array.
MySQL_fetch_object()->Fetch a result row as an object.
MySQL_fetch_row()->Fetch a result set as an array().

25. If we login more than one browser window at the same time with same user and after that we close one window then is the session is exist to other window or not.And if yes then why? or if no then why?

session depends on browser. if browser is closed then session is lost. the session data will be deleted after session time out. if connection is lost and u recreate connection, then also sesssion will continue in the browser.

27. What is the maximum storage capacity of Mysql data,
Is Mysql not reliable, Why?

28. What are the database files stored in system?
Ans: data¡¯s are stored in name.Myd
table Structure are name.$frm
Index tables are name.myi

29. what is the difference between groupby and order by in mysql?
Ans: Group by which is used to sort a table interms of colums
order by which is used to index a table by colum value