Questions: 1 Answers: 1: More Details

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Questions : 1What is Full form of PHP ? Who is the father or inventor of PHP ?

Answers : 1 Rasmus Lerdorf is known as the father of PHP that started development of PHP in 1994

for their own Personal Home Page (PHP) and they released PHP/FI (Forms Interpreter) version 1.0 publicly on 8 June 1995 But in 1997 two Israeli developers named Zeev Suraski and Andi Gutmans rewrote the parser that formed the base of PHP 3 and then changed the language's name to the PHP: Hypertext Preprocessor.

Questions : What are the differences between PHP3 and PHP4 and PHP5 ? what is the current stable 2 version of PHP ? what advance thing in php6 Answers : 2 The current stable version of PHP is PHP 5.4.6 on 2012-08-16 as still waiting for PHP6 with unicode handlig thing There are lot of difference among PHP3 and PHP4 and PHP5 version of php so Difference mean oldest version have less functionality as compare to new one like 1>PHP3 is oldest stable version and it was pure procedural language constructive like C 2>Where as PHP4 have some OOPs concept added like class and object with new functionality 3>and in PHP5 approximately all major oops functionality has been added along with below thing 1. Implementation of exceptions and exception handling 2. Type hinting which allows you to force the type of a specific argument 3. Overloading of methods through the __call function 4. Full constructors and destructors etc through a __constuctor and __destructor function 5. __autoload function for dynamically including certain include files depending on the class you are trying to create. 6 Finality : can now use the final keyword to indicate that a method cannot be overridden by a child. You can also declare an entire class as final which prevents it from having any children at all. 7 Interfaces & Abstract Classes 8 Passed by Reference : 9 An __clone method if you really want to duplicate an object 10 Numbers of Functions Deprecated or removed in PHP 5.x like ereg,ereg_replace,magic_quotes, session_register,register_globals, split(), call_user_method() etc Questions : Is variable name casesensitive ? could we start a variale with number like $4name ? What 3 is the difference between $name and $$name? Answer : 3 Yes variable name casesensitive and we can not start a variable with number like $4name as A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. where as $$ is variable of variable $name is variable where as $$name is variable of variable like $name=sonia and $$name=singh so $sonia value is singh. Questions : What is use of header() function in php ? What the Limitation of HEADER()? 4 Answers : 4 In PHP Important to notice the Limitation of HEADER() function is that header() must be called before any actual output is send. Means must use header function before HTML or any echo stateament There are Number of Use of HEADER() function in php like below 1> The header() function use to sends a raw HTTP header to a client. 2> We can use herder() function for redirection of pages. 3> Use for refresh the page on given time interval automatically. 4> To send email header content like cc, bcc , reply to etc data and lot more . Questions : How can we extract string "pcds.co.in " from a string "http://info@pcds.co.in 5 using regular expression of PHP? More on Reg can you explain Answers : 5 We can extract string "pcds.co.in" using this preg_match("/^http:\/\/.+@(.+)$/","http://info@pcds.co.in",$matches); echo $matches[1]; On regular expression interview question with very nice examples in

More Details

Questions : How do you connet mysql database with PHP ? 6 Answer : 6 We can connect Mysql Database with PHP using both Procedural and Object oriented style like below $link = mysqli_connect("localhost", "username", "password", "dbofpcds"); $mysqli = new mysqli("localhost", "username", "password", "dbname"); and in old type of connectivity were $link = mysql_connect("localhost", "username", "password"); mysql_select_db("database",$link);

Questions : In how many ways we can retrieve the data in the result set of 7 MySQL using PHP? What is the difference between mysql_fetch_object and mysql_fetch_array ? Answers : 7 we can retrieve the data in the result set of MySQL using PHP in 4 Ways 1. mysqli_fetch_row >> Get a result row as an enumerated array 2. mysqli_fetch_array >> Fetch a result row as associative and numeric array 3.mysqli_fetch_object >> Returns the current row of a result set as an object 4. mysqli_fetch_assoc >> Fetch a result row as an associative array mysqli_fetch_object() is similar to mysqli_fetch_array(), with one difference an object is returned, instead of an array. Indirectly, that means that we can only access the data by the field names, and not by their offsets (numbers are illegal property names). Questions : How can we create a database using PHP and MySQL? 8 Answers : 8 We can create MySQL database with the use of mysql_create_db("Database Name") Questions : What are the differences between require and include? 9 Answers : 9 Both include and require used to include a file but when included file not found Include send Warning where as Require send Fatal Error . Questions : Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"? 10 Answers : Yes we can use include("xyz.php") more than one time in any page. but it create a prob when 10 xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a prob Questions : What are the different tables(Engine) present in MySQL, which one is default? 11 Answers : Following tables (Storage Engine) we can create 11 1. MyISAM(The default storage engine IN MYSQL 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. An .frm file stores the table format. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. ) 2. InnoDB(InnoDB is a transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data.) 3. Merge 4. Heap (MEMORY)(The MEMORY storage engine creates tables with contents that are stored in memory. Formerly, these were known as HEAP tables. MEMORY is the preferred term, although HEAP remains supported for backward compatibility. ) 5. BDB (BerkeleyDB)(Sleepycat Software has provided MySQL with the Berkeley DB transactional storage engine. This storage engine typically is called BDB for short. BDB tables may have a greater chance of surviving crashes and are also capable of COMMIT and ROLLBACK operations on transactions) 6. EXAMPLE 7. FEDERATED (It is a storage engine that accesses data in tables of remote databases rather than in local tables. ) 8. ARCHIVE (The ARCHIVE storage engine is used for storing large amounts of data without indexes in a very small footprint. ) 9. CSV (The CSV storage engine stores data in text files using comma-separated values format.) 10. BLACKHOLE (The BLACKHOLE storage engine acts as a "black hole" that accepts data but throws it away and does not store it. Retrievals always return an empty result) Questions : What are the differences between Get and post methods. 12 Answers : There are some defference between GET and POST method 12 1. GET Method have some limit like only 2Kb data able to send for request But in POST method unlimited data can we send 2. when we use GET method requested data show in url but Not in POST method so POST method is good for send sensetive request

Questions : How can I execute a PHP script using command line? 13 Answers : Just run the PHP CLI (Command Line Interface) program and 13 provide the PHP script file name as the command line argument. Questions : Suppose your Zend engine supports the mode <? ?> Then how can u 14 configure your PHP Zend engine to support <?PHP ?> mode ? Answers : In php.ini file: 14 set short_open_tag=on to make PHP support Questions : Shopping cart online validation i.e. how can we configure Paypal, 15 etc.? Answers : Nothing more we have to do only redirect to the payPal url after 15 submit all information needed by paypal like amount,adresss etc. Questions : What is meant by nl2br()? 16 Answers : Inserts HTML line breaks (<BR />) before all newlines in a string. 16 Questions : What is htaccess? Why do we use this and Where? 17 Answers : .htaccess files are configuration files of Apache Server which provide 17 a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof. Questions : How we get IP address of client, previous reference page etc ? 18 Answers : By using $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_REFERER'] etc. 18 Questions : What are the reasons for selecting lamp (Linux, apache, MySQL, 19 PHP) instead of combination of other software programs, servers and operating systems? Answers : All of those are open source resource. Security of Linux is very 19 very more than windows. Apache is a better server that IIS both in functionality and security. MySQL is world most popular open source database. PHP is more faster that asp or any other scripting language. Questions : How can we encrypt and decrypt a data present in a MySQL table 20 using MySQL? Answers : AES_ENCRYPT () and AES_DECRYPT () 20 Questions : How can we encrypt the username and password using PHP? 21 Answers : The functions in this section perform encryption and decryption, and 21 compression and uncompression:

encryption AES_ENCRYT() ENCODE() DES_ENCRYPT() ENCRYPT() MD5() OLD_PASSWORD() PASSWORD() SHA() or SHA1()

decryption AES_DECRYPT() DECODE() DES_DECRYPT() Not available Not available Not available Not available Not available

Not available

UNCOMPRESSED_LENGTH()

Questions : What are the features and advantages of object-oriented 22 programming? Answers : One of the main advantages of OO programming is its ease of 22 modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system Questions : What are the differences between procedure-oriented languages and 23 object-oriented languages? Answers : There are lot of difference between procedure language and object oriented like below 23 1>Procedure language easy for new developer but complex to understand whole software as compare to object oriented model 2>In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern 3>IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE . Questions : What is the use of friend function? 24 Answers : Sometimes a function is best shared among a number of different 24 classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class. A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match. Questions : What are the differences between public, private, protected, 25 static, transient, final and volatile? Answer : 25 Public: Public declared items can be accessed everywhere. Protected: Protected limits access to inherited and parent classes (and to the class that defines the item). Private: Private limits visibility only to the class that defines the item. Static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope. Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended. transient: A transient variable is a variable that may not be serialized. volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time. Questions : What are the different types of errors in PHP? 26 Answer : 26 Three are three types of errors:1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script for example, accessing a variable that has not yet been defined. By default,

such errors are not displayed to the user at all although, as you will see, you can change this default behavior.2. Warnings: These are more serious errors for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.3. Fatal errors: These are critical errors for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place. Questions : What is the functionality of the function strstr and stristr? 27 Answers : strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to 27 the end of string. $email= 'sonialouder@gmail.com'; $domain = strstr($email, '@'); echo $domain; // prints @gmail.com here @ is the needle stristr is case-insensitive means able not able to diffrenciate between a and A Questions : How can we submit a form without a submit button? 28 Answer : 28 Java script submit() function is used for submit form without submit button on click call document.formname.submit() Questions : How can we convert asp pages to PHP pages? 29 Answer : 29 there are lots of tools available for asp to PHP conversion. you can search Google for that. the best one is available athttp://asp2php.naken.cc./ Questions : What is the functionality of the function htmlentities? 30 Answer : 30 Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities. Questions : How can we get second of the current time using date function? 31 Answer : 31 $second = date("s"); Questions : How can we convert the time zones using PHP? 32 Answer : 32 For convert the time zones using PHP we have to first set time zone By using PHP function date_default_timezone_set() If we want to set time zone of 'Europe/London' we have to call this funtion as date_default_timezone_set('Europe/London') so Now generate the timestamp for that particular timezone, on Sept 1st, 2012 at 8 am $pcds = mktime(8, 0, 0, 9, 1, 2012); Now set the other timezone like US/Eastern date_default_timezone_set('US/Eastern'); date(DATE_RFC1123, $pcds) date(DATE_RFC1123, $pcds) Output the date in a standard format (RFC1123) Questions : What is meant by urlencode and urldocode? 33 Answer : 33 URLencode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. urldecode decodes any

%##

encoding in the given string.

Questions : What is the difference between the functions unlink and unset? 34 Answer : 34 unlink() deletes the given file from the file system. unset() makes a variable undefined. Questions : How can we register the variables into a session? 35 Answer : 35 $_SESSION['name'] = "sonia"; Questions : How can we get the properties (size, type, width, height) of an 36 image using PHP image functions? Answer : 36 To know the Image type use exif_imagetype () function To know the Image size use getimagesize () function To know the image width use imagesx () function To know the image height use imagesy() function t Questions : How can we get the browser properties using PHP? 37 Answer : 37 By using

$_SERVER['HTTP_USER_AGENT'] variable.
Questions : What is the maximum size of a file that can be uploaded using PHP 38 and how can we change this? Answer : 38 By default the maximum size is 2MB. and we can change the following setup at php.iniupload_max_filesize = 2M Questions : How can we increase the execution time of a PHP script? 39 Answer : 39 by changing the following setup at php.inimax_execution_time = 30 ; Maximum execution time of each script, in seconds Questions : How can we take a backup of a MySQL table and how can we restore 40 it. ? Answer : 40 To backup: BACKUP TABLE tbl_name[,tbl_name] TO '/path/to/backup/directory' RESTORE TABLE tbl_name[,tbl_name] FROM '/path/to/backup/directory'mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table. -t, no-create-info Don't write table creation information (the CREATE TABLE statement). -d, no-data Don't write any row information for the table. This is very useful if you just want to get a dump of the structure for a table! Questions : How can we optimize or increase the speed of a MySQL select 41 query? Answer : 41 first of all instead of using select * from table1, use select column1, column2, column3.. from table1 Look for the opportunity to introduce index in the table you are querying. use limit keyword if you are looking for any specific number of rows from the result set.

Questions : How many ways can we get the value of current session id? 42 Answer : 42 session_id() returns the session id for the current session. Questions : How can we destroy the session, how can we unset the variable of 43 a session? Answer : 43 session_unregister Unregister a global variable from the current

session session_unset Free all session variables Questions : How can we set and destroy the cookie n php? 44 Answer : 44 By using setcookie(name, value, expire, path, domain); function we can set the cookie in php ; Set the cookies in past for destroy. like setcookie("user", "sonia", time()+3600); for set the cookie setcookie("user", "", time()-3600); for destroy or delete the cookies; Questions : How many ways we can pass the variable through the navigation 45 between the pages? Answer : 45 GET/QueryString

POST

Questions : What is the difference between ereg_replace() and eregi_replace()? 46 Answer : 46 eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters. Questions : What are the different functions in sorting an array? 47 Answer : 47 Sort(), arsort(), asort(), ksort(), natsort(), natcasesort(), rsort(), usort(), array_multisort(), and uksort(). Questions : How can we know the count/number of elements of an array? 48 Answer : 48 2 ways a) sizeof($urarray) This function is an alias of count() b) count($urarray) Questions : what is session_set_save_handler in PHP? 49 Answer : 49 session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database. Questions : How can I know that a variable is a number or not using a 50 JavaScript? Answer : 50 bool is_numeric ( mixed var) Returns TRUE if var is a number or a numeric string, FALSE otherwise.or use isNaN(mixed var)The isNaN() function is used to check if a value is not a number. Questions : List out some tools through which we can draw E-R diagrams for 51 mysql. Answer : 51 Case Studio Smart Draw Questions : How can I retrieve values from one database server and store them 52 in other database server using PHP? Answer : 52 we can always fetch from one database and rewrite to another. here is a nice solution of it.$db1 = mysql_connect("host","user","pwd") mysql_select_db("db1", $db1); $res1 = mysql_query("query",$db1);$db2 = mysql_connect("host","user","pwd") mysql_select_db("db2", $db2); $res2 = mysql_query("query",$db2);At this point you can only fetch records from you previous

ResultSet, i.e $res1 But you cannot execute new query in $db1, even if you supply the link as because the link was overwritten by the new db.so at this point the following script will fail $res3 = mysql_query("query",$db1); //this will failSo how to solve that? take a look below. $db1 = mysql_connect("host","user","pwd") mysql_select_db("db1", $db1); $res1 = mysql_query("query",$db1); $db2 = mysql_connect("host","user","pwd", true) mysql_select_db("db2", $db2); $res2 = mysql_query("query",$db2); So mysql_connect has another optional boolean parameter which indicates whether a link will be created or not. as we connect to the $db2 with this optional parameter set to 'true', so both link will remain live. now the following query will execute successfully. $res3 = mysql_query("query",$db1); Questions : List out the predefined classes in PHP? 53 Answer : 53 Directory stdClass __PHP_Incomplete_Class exception php_user_filter Questions : How can I make a script that can be bi-language (supports 54 English, German)? Answer : 54 You can maintain two separate language file for each of the language. all the labels are putted in both language files as variables and assign those variables in the PHP source. on runtime choose the required language option. Questions : What are the difference between abstract class and interface? 55 Answer : 55 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. Questions : How can we send mail using JavaScript? 56 Answer : 56 JavaScript does not have any networking capabilities as it is designed to work on client site. As a result we can not send mails using JavaScript. But we can call the client side mail protocol mailto via JavaScript to prompt for an email to send. this requires the client to approve it. Questions : How can we repair a MySQL table? 57 Answer : 57 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 Questions : What are the advantages of stored procedures, triggers, indexes? 58 Answer : 58 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. Questions : What is the maximum length of a table name, database name, and 59 fieldname in MySQL? Answer : 59 The following table describes the maximum length for each type of identifier.

Maximum Length (bytes) Database 64 Table 64 Column 64 Index 64 Alias 255 Identifier
There are some restrictions on the characters that may appear in identifiers: Questions : How many values can the SET function of MySQL take? 60 Answer : 60 MySQL set can take zero or more values but at the maximum it can take 64 values Questions : What are the other commands to know the structure of table using 61 MySQL commands except explain command? Answer : 61 describe Table-Name; Questions : How many tables will create when we create table, what are they? 62 Answer : 62 The '.frm' file stores the table definition. The data file has a '.MYD' (MYData) extension. The index file has a '.MYI' (MYIndex) extension, Questions : What is the purpose of the following files having extensions 1) .frm 63 2) .myd 3) .myi? What do these files contain? Answer : 63 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,

Questions : What is maximum size of a database in MySQL? 64 Answer : 64 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 LimitLinux 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 Questions : Give the syntax of Grant and Revoke commands? 65 Answer : 65 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 privileges b) combination of create, drop, select, insert, update and delete etc.We can grant rights on all databse by using *.* 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 userThe generic syntax for revoke is as following > REVOKE [rights] on [database/s] FROM [username@hostname] now rights can be as explained above a) All privileges 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 Questions : Explain Normalization concept? 66 Answer : 66 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 FormThe 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 FormWhere 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 Questions : How can we find the number of rows in a table using MySQL? 67 Answer : 67 Use this for mysql >SELECT COUNT(*) FROM table_name; Questions : How can we find the number of rows in a result set using PHP? 68 Answer : 68 $result = mysql_query($sql, $db_link);

$num_rows = mysql_num_rows($result); echo "$num_rows rows found";


Questions : How many ways we can we find the current date using MySQL? 69 Answer : 69 SELECT CURDATE(); CURRENT_DATE() = CURDATE() for time use SELECT CURTIME(); CURRENT_TIME() = CURTIME() Questions : What are the advantages and disadvantages of Cascading Style 70 Sheets? Answer : 70 External Style SheetsAdvantagesCan 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 contextsDisadvantagesAn 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 definitionsEmbedded 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 Questions : What type of inheritance that PHP supports? 71 Answer : 71 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'. Questions : What is the difference between Primary Key and 72 Unique key? Answer : 72 Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL. Unique Key: Unique Keys are used to uniquely identify each row in the table. There can be one and only one row for each unique key value. So NULL can be a unique key.There can be only one primary key for a table but there can be more than one unique for a table. Question : what is garbage collection? default time ? refresh time? 73 Answer : 73 Garbage Collection is an automated part of PHP , If the Garbage Collection process runs, it then analyzes any files in the /tmp for any session files that have not been accessed in a certain amount of time and physically deletes them. Garbage Collection process only runs in the default session save directory, which is /tmp. If you opt to save your sessions in a different directory, the Garbage Collection process will ignore it. the Garbage Collection process does not differentiate between which sessions belong to whom when run. This is especially important note on shared web servers. If the process is run, it deletes ALL files that have not been accessed in the directory. There are 3 PHP.ini variables, which deal with the garbage collector: PHP ini value name default session.gc_maxlifetime 1440 seconds or 24 minutes session.gc_probability 1 session.gc_divisor 100 Questions : What are the advantages/disadvantages of MySQL and PHP? 74 Answer : 74 Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP. Questions : What is the difference between GROUP BY and ORDER BY in Sql? 75 Answer : 75 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 Questions : What is the difference between char and varchar data types? 76 Answer : 76 Set char to occupy n bytes and it will take n bytes even if u r storing a value of n-m bytes Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes eg. name char(15) will waste 10 bytes if we store 'romharshan', if each char takes a byte eg. name varchar(15) will just use 5 bytes if we store 'romharshan', if each char takes a byte. rest 10 bytes will be free. Questions : What is the functionality of md5 function in PHP? 77 Answer : 77 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. Questions : How can I load data from a text file into a table? 78 Answer : 78 you can use LOAD DATA INFILE file_name; syntax to load data from a text file. but you have to make sure thata) data is delimited b) columns and data matched correctly Questions : How can we know the number of days between two given dates using 79 MySQL?

Answer : 79 SELECT DATEDIFF("2007-03-07","2005-01-01"); Questions : How can we know the number of days between two given dates using PHP? 80 Answer : 80 $date1 = date("Y-m-d"); $date2 = "2006-08-15"; $days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24); Questions : How we load all classes that placed in different directory in one PHP File , means how to do 81 auto load classes Answer : 81 by using spl_autoload_register('autoloader::funtion'); Like below class autoloader { public static function moduleautoloader($class) { $path = $_SERVER['DOCUMENT_ROOT'] . "/modules/{$class}.php"; if (is_readable($path)) require $path; } public static function daoautoloader($class) { $path = $_SERVER['DOCUMENT_ROOT'] . "/dataobjects/{$class}.php"; if (is_readable($path)) require $path; } public static function includesautoloader($class) { $path = $_SERVER['DOCUMENT_ROOT'] . "/includes/{$class}.php"; if (is_readable($path)) require $path; } } spl_autoload_register('autoloader::includesautoloader'); spl_autoload_register('autoloader::daoautoloader'); spl_autoload_register('autoloader::moduleautoloader');

Questions : How many types of Inheritances used in PHP and how we achieve it 82 Answer : 82 As far PHP concern it only support single Inheritance in scripting. we can also use interface to achieve multiple inheritance. Questions : PHP how to know user has read the email? 83

Answers : 83

Using Disposition-Notification-To: in mailheader we can get read receipt. Add the possibility to define a read receipt when sending an email. Its quite straightforward, just edit email.php, and add this at vars definitions: var $readReceipt = null; And then, at createHeader function add: if (!empty($this->readReceipt)) { $this->__header .= Disposition-Notification-To: . $this->__formatAddress($this>readReceipt) . $this->_newLine; }

Questions : What are default session time and path? 84 Answers : default session time in PHP is 1440 seconds or 24 minutes 84 Default session save path id temporary folder /tmp Questions : how to track user logged out or not? when user is idle ? 85 Answers : By checking the session variable exist or not while loading th page. As the session will exist longer as 85 till browser closes. The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server. Questions : how to track no of user logged in ? 86 Answers : whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out 86 or sesion expire make it inactive. At any time by counting the no: of active records we can get the no: of visitors. Questions : in PHP for pdf which library used? 87 Answers : The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an 87 object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the Panda module. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5. Questions : for image work which library? 88 Answers : we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may 88 also require other libraries, depending on which image formats you want to work with. Questions : what is design pattern? singleton pattern? 89 Answers : A design pattern is a general reusable solution to a commonly occurring problem in software design. 89 The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves. Questions : what are magic methods? 90 Answers : Magic methods are the members functions that is available to all the instance of class Magic methods 90 always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone() Questions : what is magic quotes? 91 Answers : Magic Quotes is a process that automagically escapes ncoming data to the PHP script. Its 91 preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. Questions : what is cross site scripting? SQL injection? 92

Answers : 92

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts. SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed

Questions : what is URL rewriting? 93 Answers : Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better 93 than Dynamic URLs because of a number of reasons 1. Static URLs typically Rank better in Search Engines. 2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages. 3. Static URLs are always more friendlier looking to the End Users. along with this we can use URL rewriting in adding variables [cookies] to the URL to handle the sessions. Questions : what is the major php security hole? how to avoid? 94 Answers : 1. Never include, require, or otherwise open a file with a filename based on user input, without 94 thoroughly checking it first. 2. Be careful with eval() Placing user-inputted values into the eval() function can be extremely dangerous. You essentially give the malicious user the ability to execute any command he or she wishes! 3. Be careful when using register_globals = ON It was originally designed to make programming in PHP easier (and that it did), but misuse of it often led to security holes 4. Never run unescaped queries 5. For protected areas, use sessions or validate the login every time. 6. If you dont want the file contents to be seen, give the file a .php extension. Questions : whether PHP supports Microsoft SQL server ? 95 Answers : The SQL Server Driver for PHP v1.0 is designed to enable reliable, scalable integration with SQL 95 Server for PHP applications deployed on the Windows platform. The Driver for PHP is a PHP 5 extension that allows the reading and writing of SQL Server data from within PHP scripts. using MSSQL or ODBC modules we can access Microsoft SQL server. Questions : what is MVC? why its been used? 96 Answers : Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use 96 of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model. WHY ITS NEEDED IS 1 Modular separation of function 2 Easier to maintain 3 View-Controller separation means: A Tweaking design (HTML) without altering code B Web design staff can modify UI without understanding code Questions : what is framework? how it works? what is advantage? 97 Answers : In general, a framework is a real or conceptual structure intended to serve as a support or guide for 97 the building of something that expands the structure into something useful. Advantages : Consistent Programming Model Direct Support for Security Simplified Development Efforts Easy Application Deployment and Maintenance Questions : what is CURL? 98 Answers : CURL means Client URL Library 98 curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos), file transfer resume, proxy tunneling and a busload of other useful tricks. CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap

protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHPs ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication. Questions : what is PDO ? 99 Answers : The PDO ( PHP Data Objects ) extension defines a lightweight, consistent interface for accessing 99 databases in PHP. if you are using the PDO API, you could switch the database server you used, from say PgSQL to MySQL, and only need to make minor changes to your PHP code. While PDO has its advantages, such as a clean, simple, portable API but its maindisadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server. For example, PDO does not allow you to use MySQL's support for Multiple Statements. Just need to use below code for connect mysql using PDO try { $dbh = new PDO("mysql:host=$hostname;dbname=databasename", $username, $password); $sql = "SELECT * FROM employee"; foreach ($dbh->query($sql) as $row) { print $row['employee_name'] .' - '. $row['employee_age'] ; } } catch(PDOException $e) { echo $e->getMessage(); } Questions : What is PHP's mysqli Extension? 100 Answers : The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to 100 take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later. The mysqli extension has a number of benefits, the key enhancements over the mysql extension being: =>Object-oriented interface =>Support for Prepared Statements =>Support for Multiple Statements =>Support for Transactions =>Enhanced debugging capabilities =>Embedded server support

Questions : What is PHP Object Oriented Programming ? 1 Answers : It is a problem solving technique to develop software systems. It is a technique to think real world in 1

terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects.

Questions What is a Class ? :2 Answers : A class describes all the attributes of objects, as well as the methods that implement the behavior of 2 member objects. It is a comprehensive data type which represents a blue print of objects. Its a template of object. Questions What is an Object ? :3 Answers : It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects 3 are members of a class. Attributes and behavior of an object are defined by the class definition. Questions What is the relation between Classes and Objects? :4 Answers : They look very much same but are not same. Class is a definition, while object is instance of the class

created. Class is a blue print while objects are actual objects existing in real world. Example we have class CAR which has attributes and methods like Speed, Brakes, Type of Car etc.Class CAR is just a prototype, now we can create real time objects which can be used to provide functionality. Example we can create a Maruti car object with 100 km speed and urgent brakes.

Questions What are different properties provided by Object-oriented systems ? :5 Answers : Following are characteristics of Object Oriented Systems:5 Abstraction It allows complex real world to be represented in simplified manner. Example color is abstracted to RGB.By just making the combination of these three colors we can achieve any color in world. Its a model of real world or concept. Encapsulation The process of hiding all the internal details of an object from the outside world. Communication Using messages when application wants to achieve certain task it can only be done using combination of objects. A single object can not do the entire task. Example if we want to make order processing form. We will use Customer object, Order object, Product object and Payment object to achieve this functionality. In short these objects should communicate with each other. This is achieved when objects send messages to each other. Object lifetime All objects have life time. Objects are created, initialized, necessary functionalities are done and later the object is destroyed. Every object have there own state and identity, which differ from instance to instance. Questions What is an Abstract class ? :6 Answers : Abstract class defines an abstract concept which can not be instantiated and comparing o interface it 6 can have some implementation while interfaces can not. Below are some points for abstract class:=>We can not create object of abstract class it can only be inherited in a below class. => Normally abstract classes have base implementation and then child classes derive from the abstract class to make the class concrete. Questions What are Abstract methods? :7 Answers : Abstract class can contain abstract methods. Abstract methods do not have implementation. Abstract 7 methods should be implemented in the subclasses which inherit them. So if an abstract class has an abstract method class inheriting the abstract class should implement the method or else java compiler will through an error. In this way, an abstract class can define a complete programming interface thereby providing its subclasses with the method declarations for all of the methods necessary to implement that programming interface. Abstract methods are defined using "abstract" keyword. Below is a sample code snippet. abstract class pcdsGraphics { abstract void draw(); } Any class inheriting from "pcdsGraphics" class should implement the "draw" method or else the java compiler will throw an error. so if we do not implement a abstract method the program will not compile. Questions What is the difference between Abstract classes and Interfaces ? :8 Answers : Difference between Abstract class and Interface is as follows:8 Abstract class can only be inherited while interfaces can not be it has to be implemented. Interface cannot implement any methods, whereas an abstract class can have implementation.

Class can implement many interfaces but can have only one super class. Interface is not part of the class hierarchy while Abstract class comes in through inheritance. Unrelated classes can implement the same interface. Questions What is difference between Static and Non-Static fields of a class ? :9 Answers : Non-Static values are also called as instance variables. Each object of the class has its own copy of 9 Non-Static instance variables. So when a new object is created of the same class it will have completely its own copy of instance variables. While Static values have only one copy of instance variables and will be shared among all the objects of the class. Questions What are inner classes and what is the practical implementation of inner classes? : 10 Answers : Inner classes are nested inside other class. They have access to outer class fields and methods even if 10 the fields of outer class are defined as private. public class Pcds { class pcdsEmp { // inner class defines the required structure String first; String last; } // array of name objects clsName personArray[] = {new clsName(), new clsName(), new clsName()}; } Normally inner classes are used for data structures like one shown above or some kind of helper classes. Questions What is a constructor in class? : 11 Answers : Constructor has the same name as the class in which it resides and looks from syntax point of view it 11 looks similiar to a method. Constructor is automatically called immediately after the object is created, before the new operator completes. Constructors have no return type, not even void. This is because the implicit return type of a class' constructor is the class type itself. It is the constructor's job to initialize the internal state of an object so that the code creating an instance will have a fully initialized, usable object immediately. Questions Can constructors be parameterized? : 12 Answers : Yes we can have parameterized constructor which can also be termed as constructor overloading. 12 Below is a code snippet which shows two constructors for pcdsMaths class one with parameter and one with out. class pcdsMaths { double PI; // This is the constructor for the maths constant class. pcdsMaths() {PI = 3.14;} pcdsMaths(int pi) { PI = pi; }} Questions What is the use if instanceof keyword? and How do refer to a current instance of object? : 13

Answers : "instanceof" keyword is used to check what is the type of object. 13 we can refer the current instance of object using "this" keyword. For instance if we have class which has color property we can refer the current object instance inside any of the method using "this.color". Questions what is Bootstrap, Extension and System Class loader? or Can you explain primordial class : 14 loader? Answers : There three types of class loaders:14 BootStrap Class loader also called as primordial class loader. Extension Class loader. System Class loader. Lets now try to get the fundamentals of these class loaders. Bootstrap Class loader Bootstrap class loader loads those classes those which are essential for JVM to function properly. Bootstrap class loader is responsible for loading all core java classes for instance java.lang.*, java.io.* etc. Bootstrap class loader finds these necessary classes from jdk/ jre/lib/rt.jar. Bootstrap class loader can not be instantiated from JAVA code and is implemented natively inside JVM. Extension Class loader The extension class loader also termed as the standard extensions class loader is a child of the bootstrap class loader. Its primary responsibility is to load classes from the extension directories, normally located the jre/lib/ext directory. This provides the ability to simply drop in new extensions, such as various security extensions, without requiring modification to the user's class path. System Class loader The system class loader also termed application class loader is the class loader responsible for loading code from the path specified by the CLASSPATH environment variable. It is also used to load an applications entry point class that is the "static void main ()" method in a class. Questions whats the main difference between ArrayList / HashMap and Vector / Hashtable? : 15 Answers : Vector / HashTable are synchronized which means they are thread safe. Cost of thread safe is 15 performance degradation. So if you are sure that you are not dealing with huge number of threads then you should use ArrayList / HashMap.But yes you can still synchronize List and Maps using Collections provided methods :List OurList = Collections.synchronizedList (OurList); Map OurMap = Collections.synchronizedMap (OurMap); Questions What are access modifiers? : 16 Answers : Access modifiers decide whether a method or a data variable can be accessed by another method in 16 another class or subclass. four types of access modifiers: Public: - Can be accessed by any other class anywhere. Protected: - Can be accessed by classes inside the package or by subclasses ( that means classes who inherit from this class). Private - Can be accessed only within the class. Even methods in subclasses in the same package do not have access. Default - (Its private access by default) accessible to classes in the same package but not by classes in other packages, even if these are subclasses. Questions Define exceptions ? : 17 Answers : An exception is an abnormal condition that arises in a code sequence at run time. Basically there are 17 four important keywords which form the main pillars of exception handling: try, catch, throw and finally. Code which you want to monitor for exception is contained in the try block. If any exception occurs in the try block its sent to the catch block which can handle this error in a more rational manner. To throw an exception manually you need to call use the throw keyword. If you want to put

any clean up code use the finally block. The finally block is executed irrespective if there is an error or not. Questions What is serialization?How do we implement serialization actually? : 18 Answers : Serialization is a process by which an object instance is converted in to stream of bytes. There are 18 many useful stuff you can do when the object instance is converted in to stream of bytes for instance you can save the object in hard disk or send it across the network. In order to implement serialization we need to use two classes from java.io package ObjectOutputStream and ObjectInputStream. ObjectOutputStream has a method called writeObject, while ObjectInputStream has a method called readObject. Using writeobject we can write and readObject can be used to read the object from the stream. Below are two code snippet which used the FileInputStream and FileOutputstream to read and write from harddisk.

Mysql interview questions and answers are below


'
Questions how to do login in mysql with unix shell :1 Answers By below method if password is pass and user name is root :1 # [mysql dir]/bin/mysql -h hostname -u root -p pass Questions how you will Create a database on the mysql server with unix shell :2 Answers : mysql> create database databasename; 2 Questions how to list or view all databases from the mysql server. :3 Answers : mysql> show databases; 3 Questions How Switch (select or use) to a database. :4 Answers : mysql> use databasename; 4 Questions How To see all the tables from a database of mysql server. :5 Answers : mysql> show tables; 5 Questions How to see table's field formats or description of table . :6 Answers : mysql> describe tablename; 6 Questions How to delete a database from mysql server. :7 Answers : mysql> drop database databasename; 7 Questions How we get Sum of column :8 Answers : mysql> SELECT SUM(*) FROM [table name]; 8 Questions How to delete a table :9 Answers : mysql> drop table tablename; 9

Questions How you will Show all data from a table. : 10 Answers : mysql> SELECT * FROM tablename; 10 Questions How to returns the columns and column information pertaining to the : 11 designated table Answers : mysql> show columns from tablename; 11 Questions How to Show certain selected rows with the value "pcds" : 12 Answers : mysql> SELECT * FROM tablename WHERE fieldname = "pcds"; 12 Questions : 13 Answers : 13 Questions : 14 Answer : 14 Questions : 15 Answers : 15 Questions : 16 Answers : 16 How will Show all records containing the name "sonia" AND the phone number '9876543210' mysql> SELECT * FROM tablename WHERE name = "sonia" AND phone_number = '9876543210'; How you will Show all records not containing the name "sonia" AND the phone number '9876543210' order by the phone_number field. mysql> SELECT * FROM tablename WHERE name != "sonia" AND phone_number = '9876543210' order by phone_number; How to Show all records starting with the letters 'sonia' AND the phone number '9876543210' mysql> SELECT * FROM tablename WHERE name like "sonia%" AND phone_number = '9876543210'; How to show all records starting with the letters 'sonia' AND the phone number '9876543210' limit to records 1 through 5. mysql> SELECT * FROM tablename WHERE name like "sonia%" AND phone_number = '9876543210' limit 1,5;

Questions Use a regular expression to find records. Use "REGEXP BINARY" to force : 16 case-sensitivity. This finds any record beginning with r. Answer : mysql> SELECT * FROM tablename WHERE rec RLIKE "^r"; 16 Questions How you will Show unique records. : 17 Answer : mysql> SELECT DISTINCT columnname FROM tablename; 17 Questions how we will Show selected records sorted in an ascending (asc) or : 18 descending (desc) Answer : mysql> SELECT col1,col2 FROM tablename ORDER BY col2 DESC; 18 mysql> SELECT col1,col2 FROM tablename ORDER BY col2 ASC;

Questions how to Return total number of rows. : 19 Answers : mysql> SELECT COUNT(*) FROM tablename; 19 Questions How to Join tables on common columns. : 20 Answer : mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left 20 join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id Questions How to Creating a new user. Login as root. Switch to the MySQL db. Make the : 21 user. Update privs.

Answer : 21

# mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password')); mysql> flush privileges;

Questions How to Change a users password from unix shell. : 22 Answers : # [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new22 password' Questions How to Change a users password from MySQL prompt. Login as root. Set the : 23 password. Update privs. Answer : # mysql -u root -p 23 mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere'); mysql> flush privileges; Questions How to Recover a MySQL root password. Stop the MySQL server process. : 24 Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server. Answer : # /etc/init.d/mysql stop 24 # mysqld_safe --skip-grant-tables & # mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD("newrootpassword") where User='root'; mysql> flush privileges; mysql> quit # /etc/init.d/mysql stop # /etc/init.d/mysql start Questions How to Set a root password if there is on root password. : 25 Answer : # mysqladmin -u root password newpassword 25 Questions How to Update a root password. : 26 Answer : # mysqladmin -u root -p oldpassword newpassword 26 Questions How to allow the user "sonia" to connect to the server from localhost using : 27 the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs. Answers : # mysql -u root -p 27 mysql> use mysql; mysql> grant usage on *.* to sonia@localhost identified by 'passwd'; mysql> flush privileges; Questions : 28 Answers : 28 How to give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs. # mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N'); mysql> flush privileges; or mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges;

Questions How To update info already in a table and Delete a row(s) from a table. : 29 Answer : mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 29 'Y' where [field name] = 'user'; mysql> DELETE from [table name] where [field name] = 'whatever'; Questions How to Update database permissions/privilages. : 30 Answer : mysql> flush privileges; 30 Questions How to Delete a column and Add a new column to database : 31 Answer : mysql> alter table [table name] drop column [column name]; 31 mysql> alter table [table name] add column [new column name] varchar (20); Questions Change column name and Make a unique column so we get no dupes. : 32 Answer : mysql> alter table [table name] change [old column name] [new column name] 32 varchar (50); mysql> alter table [table name] add unique ([column name]); Questions How to make a column bigger and Delete unique from table. : 33 Answer : mysql> alter table [table name] modify [column name] VARCHAR(3); 33 mysql> alter table [table name] drop index [colmn name]; Questions How to Load a CSV file into a table : 34 Answer : mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] 34 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3); Questions How to dump all databases for backup. Backup file is sql commands to : 35 recreate all db's. Answer : # [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql 35 Questions How to dump one database for backup. : 36 Answer : # [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename 36 >/tmp/databasename.sql Questions How to dump a table from a database. : 37 Answer : # [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename 37 > /tmp/databasename.tablename.sql Questions Restore database (or database table) from backup. : 38 Answer : # [mysql dir]/bin/mysql -u username -ppassword databasename < 38 /tmp/databasename.sql Questions How to Create Table show Example : 39 Answer : mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial 39 VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255)); Questions How to search second maximum(second highest) salary value(integer)from : 40 table employee (field salary)in the manner so that mysql gets less load? Answers : By below query we will get second maximum(second highest) salary 40 value(integer)from table employee (field salary)in the manner so that mysql gets less load? SELECT DISTINCT(salary) FROM employee order by salary desc limit 1 , 1 ;

(This way we will able to find out 3rd highest , 4th highest salary so on just need to change limit condtion like LIMIT 2,1 for 3rd highest and LIMIT 3,1 for 4th some one may finding this way useing below query that taken more time as compare to above query SELECT salary FROM employee where salary < (select max(salary) from employe) order by salary DESC limit 1 ;

You might also like