Part2 – Interview Questions - Interview Questions
How many ways can we get the value of current session id?
Answer: session_id() returns the session id for the current session.
How can we destroy the session, how can we unset the variable of a session?
Answer: session_unregister() unregisters a global variable from the current session. session_unset() frees all session variables.
How can we destroy the cookie?
Answer:: Set the cookie in past.
How many ways we can pass the variable through the navigation between the pages?
Answer: At least 3 ways:
a) Register the variable into the session
b) Pass the variable as a cookie
c) Pass the variable as part of the URL
What is the difference between ereg_replace() and eregi_replace()?
Answer: eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.
What are the different functions in sorting an array?
Answer: Sorting functions in PHP: asort() arsort() ksort() krsort() uksort() sort() natsort() rsort()
How can we know the count/number of elements of an array?
Answer: 2 ways: a) sizeof($urarray) This function is an alias of count() b) count($urarray) Interestingly if u just pass a simple var instead of a an array it will return 1.
What is the php predefined variable that tells the What types of images that php supports?
Answer:$_SERVER['HTTP_ACCEPT']
How can I know that a variable is a number or not using a _JavaScript?
Answer: function IsNumeric(sText) { var ValidChars = “0123456789.”; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber;
}
List out some tools through which we can draw E-R diagrams for mysql.
Answer: Dbdesigner, conceptdraw etc.
How can I retrieve values from one database server and store them in other database server using php?
Answer: “.”Executed”; mysql_close($link2); ?>
List out the predefined classes in php?
Answer: Directory stdClass __PHP_Incomplete_Class
exception php_user_filter
How can I make a script that can be bilanguage (supports Eglish, German)?
Answer : You can change charset variable in above line in the script to support bilanguage.
What are the difference between abstract class and interface?
Answer:Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class. Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.
How can we send mail-using _JavaScript?
Answer: NO! JavaScript can’t email a form! but, there are alternatives to send the form data to an email address. Try this:
How can we repair a mysql table?
Answer: 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
What are the advantages of stored procedures, triggers, indexes?
Answer:A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don’t need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side.
Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted. Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.
What is the maximum length of a table name, database name, and fieldname in mysql?
Answer: Database name- 64 Table name -64 Fieldname-64
How many values can the SET function of mysql takes?
Answer: Mysql set can take zero or more values but at the maximum it can take 64 values
What are the other commands to know the structure of table using mysql commands except explain command?
Answer: describe table_name;
How many tables will create when we create table, what are they?
Answer: 3 tables will create when we create table. They are The `.frm’ file stores the table definition. The data file has a `.MYD’ (MYData) extension. The index file has a `.MYI’ (MYIndex) extension,
What is the purpose of the following files having extensions 1) frm 2) MYD 3) MYI. What these files contains?
Answer: In MySql, the default table type is MyISAM. Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. The `.frm’ file stores the table definition. The data file has a `.MYD’ (MYData) extension.
The index file has a `.MYI’ (MYIndex) extension,
What is maximum size of a database in mysql?
Answer: If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected. The amount of available disk space limits the number of tables. MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits. The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB. The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system. Operating System File-size Limit Linux 2.2-Intel 32-bit 2GB (LFS: 4GB) Linux 2.4+ (using ext3 filesystem) 4TB Solaris 9/10 16TB NetWare w/NSS filesystem 8TB Win32 w/ FAT/FAT32 2GB/4GB Win32 w/ NTFS 2TB (possibly larger) MacOS X w/ HFS+ 2TB
Give the syntax of Grant and Revoke commands?
Answer: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
Explain Normalization concept?
The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed). First Normal Form The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic). Second Normal Form Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form. Third Normal Form I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table
How can we find the number of rows in a table using mysql?
Answer: 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];
How can we find the number of rows in a result set using php?
Answer: for PHP $result = mysql_query($any_valid_sql, $database_link); $num_rows = mysql_num_rows($result); echo “$num_rows rows found”;
How many ways we can we find the current date using mysql?
Answer: SELECT CURDATE(); CURRENT_DATE() = CURDATE() for time use SELECT CURTIME(); CURRENT_TIME() = CURTIME()
What are the advantages and disadvantages of CASCADE STYLE SHEETS?
Answer:External Style Sheets Advantages Can control styles for multiple documents at once Classes can be created for use on multiple HTML element types in many documents Selector and grouping methods can be used to apply styles under complex contexts Disadvantages An extra download is required to import style information for each document The rendering of the document may be delayed until the external style sheet is loaded Becomes slightly unwieldy for small quantities of style definitions Embedded Style Sheets Advantages Classes can be created for use on multiple tag types in the document Selector and grouping methods can be used to apply styles under complex contexts No additional downloads necessary to receive style information Disadvantages This method can not control styles for multiple documents at once Inline Styles Advantages Useful for small quantities of style definitions Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods Disadvantages Does not distance style information from content (a main goal of SGML/HTML) Can not control styles for multiple documents at once Author can not create or control classes of elements to control multiple element types within the document Selector grouping methods can not be used to create complex element addressing scenarios
What type of inheritance that php supports?
Answer: In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’. Usage:
var $owner; function set_owner ($name) { $this->owner = $name; } } ?>
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
Answer: In general, when you want to make a slow SELECT … WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT. See section 7.4.5 How MySQL Uses Indexes and section 7.2.1 EXPLAIN Syntax (Get Information About a SELECT). Some general tips for speeding up queries on MyISAM tables: To help MySQL optimize queries better, use ANALYZE TABLE or run myisamchk –analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL will use this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk –description –verbose shows index distribution information. To sort an index and data according to an index, use myisamchk –sort-index –sortrecords=1 (if you want to sort on index 1). This is a good way to make queries faster if you have a unique index from which you want to read all records in order
according to the index. Note that the first time you sort a large table this way, it may take a long time. In both cases let the value for auto increment field be n then next row will have value n+1 i.e. 2346
What are the advantages/disadvantages of mysql and php?
Answer: Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP.
What is the difference between GROUP BY and ORDER BY in Sql?
Answer: To sort a result, use an ORDER BY clause. The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any). 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
What is the difference between char and varchar data types?
Answer: char(M) M bytes 0<=M<=255 varchar(M) L+1 bytes where L<=M & 0<=M<=255 i.e.; char data type allocate memory statically and varchar data type allocate memory dynamically
What is the functionality of md5 function in php?
Answer: string md5(string) Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. We can use it to generate keys, which we use to identify users etc. If we add random no techniques to it the md5 generated now will be totally different for the same string we are using..
How can I load data from a text file into a table?
Answer: 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
How can we know the number of days between two given dates using mysql?
Answer: select DIFFDATE( NOW(), ‘yyyy-mm-dd’ );
How can we know the number of days between two given dates using php?
Answer:
How can we change the name of a column of a table?
Answer:MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name [, tbl_name2 TO new_tbl_name2] …
or,ALTER TABLE tableName CHANGE OldName newName.