Custom Search

Thursday, February 28, 2013

PHP AND MYSQL


1. What are the differences between GET And POST methods in form submitting, givethe case where we can use get and we can use post methods?

On the server side, the main difference between GET and POST is where thesubmitted is stored. The $_GET array stores data submitted by the GET method.The $_POST array stores data submitted by the POST method.On the browser side, the difference is that data submitted by the GET method willbe displayed in the browser's address field. Data submitted by the POST methodwill not be displayed anywhere on the browser.GET method is mostly used for submitting a small amount and less sensitive data.POST method is mostly used for submitting a large amount or sensitive data.

2. Who is the father of php and explain the changes in php versions?

Answer:Rasmus Lerdorf for version changes go to Marco Tabini is the founder and publisher of php|architect.

3. How can we submit from without a submit button?

Answer:We can use a simple JavaScript code linked to an event trigger of any form field.In the JavaScript code, we can call the document.form.submit() function to submitthe form.

4. How many ways we can retrieve the date in result set of mysql Using php?

Answer:As individual objects so single record or as a set or arrays.

 5. What is the difference between mysql_fetch_object and mysql_fetch_array?

Answer:MySQL fetch object will collect first single matching record wheremysql_fetch_array will collect all matching records from the table in an array.

 6. What is the difference between $message and $$message?

Answer:They are both variables. But $message is a variable with a fixed name. $$message isa variable who's name is stored in $message. For example, if $message contains"var", $$message is the same as $var.


 7. How can we extract string 'abc.com ' from a string'http://info@a...' using regular _expression of php?

Answer:We can use the preg_match() function with "/.*@(.*)$/" asthe regular expression pattern. For example:preg_match("/.*@(.*)$/","http://info@abc.com",$data);echo $data[1];

8. How can we create a database using php and mysql?

Answer:PHP: mysql_create_db()Mysql: create database;

9. What are the differences between require and include, include_once?

Answer:File will not be included more than once. If we want to include a file once only andfurther calling of the file will be ignored then we have to use the PHP functioninclude_once(). This will prevent problems with function redefinitions, variablevalue reassignments, etc.

10. Can we use include ("abc.php") two times in a php page "makeit.php"?

Answer:Yes we can include..

 11. What are the different tables present in mysql, which type of table is generated whenwe are creating a table in the followingsyntax: create table employee(eno int(2),ename varchar(10)) ?

Answer:Total 5 types of tables we can create1. MyISAM2. Heap3. Merge4. InnoDB5. ISAM6. BDBMyISAM is the default storage engine as of MySQL 3.23.

12. Functions in IMAP, POP3 AND LDAP?

Answer:Please visit:http://fi2.php.net/imaphttp://uk2.php.net/ldap

13. How can I execute a php script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHPscript file name as the command line argument. For example, "php myScript.php",assuming "php" is the command to invoke the CLI program.Be aware that if your PHP script was written for the Web CGI interface, it may notexecute properly in command line environment.


14. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?

Answer:All of those are open source resource. Security of linux is very very more thanwindows. 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 orany other scripting language.

15.  How can we encrypt and decrypt a data present in a mysql table using mysql?
Answer:AES_ENCRYPT () and AES_DECRYPT ()



16. What are the different types of errors in php?

Answer:Three are three types of errors:
1.Notices: These are trivial, non-critical errors that PHP encounters whileexecuting 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 behaviour.
2.Warnings: These are more serious errors - for example, attempting to include() afile which does not exist. By default, these errors are displayed to the user, but theydo not result in script termination.
3.Fatal errors: These are critical errors - for example, instantiating an object of anon-existent class, or calling a non-existent function. These errors cause theimmediate termination of the script, and PHP's default behaviour is to display themto the user when they take place.

17. What is the functionality of the function strstr and stristr?

Answer:strstr() returns part of a given string from the first occurrence of a given substringto the end of the string. For example: strstr("user@example.com","@") will return"@example.com".stristr() is idential to strstr() except that it is case insensitive.
18. What is the functionality of the function htmlentities?

Answer:htmlentities -- Convert all applicable characters to HTML entitiesThis function is identical tohtmlspecialchars()in all ways, except withhtmlentities(), all characters which have HTML character entity equivalents aretranslated into these entities.

19. How can we get second of the current time using date function?

Answer:$second = date(“s”);
20. How can we convert the time zones using php?

Answer:

21. What is meant by urlencode and urldocode?

Answer:urlencode() returns the URL encoded version of the given string. URL codingconverts special characters into % signs followed by two hex digits. For example:urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe tobe used as part of URLs.urldecode() returns the URL decoded version of the given string.

22. What is the difference between the functions unlink and unset?

Answer:unlink() deletes the given file from the file system.unset() makes a variable undefined.

23. How can we register the variables into a session?

Answer:We can use the session_register ($ur_session_var) function.
24. How can we get the properties (size, type, width, height) of an image using phpimage functions?

Answer:To know the Image type use exif_imagetype () functionTo know the Image size use getimagesize () functionTo know the image width use imagesx () functionTo know the image height use imagesy() function

25. How can we get the browser properties using php?

Answer:

26. What is the maximum size of a file that can be uploaded using php and how can wechange this?
Answer:You can change maximum size of a file set upload_max_filesize variable in php.inifile

27. How can we increase the execution time of a php script?

Answer:Set max_execution_time variable in php.ini file to your desired time in second.

28. How many ways can we get the value of current session id?

Answer:session_id() returns the session id for the current session.
43. 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.

29. How can we destroy the cookie?

Answer::Set the cookie in past.

30. 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 sessionb) Pass the variable as a cookiec) Pass the variable as part of the URL

31. What is the difference between ereg_replace() and eregi_replace()?

Answer:eregi_replace() function is identical to ereg_replace() except that this ignores casedistinction when matching alphabetic characters.

32. What are the different functions in sorting an array?

Answer:Sorting functions in PHP:asort()arsort()ksort()krsort()uksort()sort()natsort()rsort()

33. 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.

34. What is the php predefined variable that tells the What types of images that phpsupports?

Answer:
$_SERVER['HTTP_ACCEPT']


35. List out some tools through which we can draw E-R diagrams for mysql.

Answer:Dbdesigner, conceptdraw etc.


36. List out the predefined classes in php?

Answer:DirectorystdClass__PHP_Incomplete_Class
exceptionphp_user_filter


37. What are the difference between abstract class and interface?

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 themethods, which are declare in its class but not define. The definition of thosemethods must be in its extending class.Interface: Interfaces are one type of class where all the methods are abstract. Thatmeans all the methods only declared but not defined. All the methods must be defineby its implemented class.

38. How can we repair a mysql table?

Answer:The syntex for repairing a mysql table isREPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]This command will repair the table specifiedif the quick is given the mysql will do a repair of only the index tree if the extendedis given it will create index row by row


39. What is the maximum length of a table name, database name, and fieldname inmysql?

Answer:Database name- 64Table name -64Fieldname-64

40. 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

PHP WITH MYSQL QUESTION AND ANSWERS


41. What are the other commands to know the structure of table using mysql commandsexcept explain command?

Answer:describe table_name;

42. How many tables will create when we create table, what are they?

Answer:3 tables will create when we create table. They areThe `.frm' file stores the table definition.The data file has a `.MYD' (MYData) extension.The index file has a `.MYI' (MYIndex) extension,

43. 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 beginwith 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,


44. 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 resultdo this>SELECT [colms],COUNT(*) FROM table_name [where u put conditions];

45. 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”;

46. How many ways we can we find the current date using mysql?

Answer:SELECT CURDATE();CURRENT_DATE() = CURDATE()for time useSELECT CURTIME();CURRENT_TIME() = CURTIME()

47. What type of inheritance that php supports?

Answer:In PHP an extended class is always dependent on a single base class, that is, multipleinheritance is not supported. Classes are extended using the keyword 'extends'.Usage:
var$owner;functionset_owner($name) { $this->owner=$name;}}?>


48. 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.


49. 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 thata) data is delimitedb) u match the colms and data correctly
dont use w/out first learning the syntax

50. How can we know the number of days between two given dates using mysql?
Answer:select DIFFDATE( NOW(), ‘yyyy-mm-dd’ );

51. 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.

52. How can we change the name and data type of a column of a table?

 Answer: ALTER [IGNORE] TABLE
tbl_name

alter_specification
[,
alter_specification
] | CHANGE [COLUMN]
old_col_name

column_definition

[FIRST|AFTER
col_name
]

53. What are the differences between drop a table and truncate a table?

Answer:Delete a Table or DatabaseTo delete a table (the table structure, attributes, andindexes will also be deleted).What if we only want to get rid of the data inside a table, and not the table itself?Use the TRUNCATE TABLE command (deletes only the data inside the table).

54. What is meant by MIME?

Answer:Multipurpose Internet Mail Extensions.WWW's ability to recognise and handle files of different types is largely dependenton the use of the MIME (Multipurpose Internet Mail Extensions) standard. Thestandard provides for a system of registration of file types with information aboutthe applications needed to process them. This information is incorporated into Webserver and browser software, and enables the automatic recognition and display of registered file types.

55. What is meant by PEAR in php?

Answer: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 usersA system for code distribution and package maintenanceA standard style for code written in PHPThe PHP Foundation Classes (PFC),The PHP Extension Community Library (PECL),A web site, mailing lists and download mirrors to support the PHP/PEARcommunityPEAR 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 peoplehave joined the project since then.http://pear.php.net/manual/en/introduction.php

 56. How can I load the dll’s dynamically?98. How many ways we can give the output to a browser?
Answer:HTML outputPHP, ASP, JSP, Servlet FunctionScript Language output FunctionDifferent Type of embedded Package to output to a browser

57. How can we know that a session is started or not?

Answer:a session starts by session_start()function.this session_start() is always declared in header portion.it always declares first.thenwe write session_register().

58. What is the default session time in php and how can I change it?

Answer:The default session time in php is until closing of browser

 59. What changes I have to done in php.ini file for file uploading?
Answer:Make the following Line uncomment like:; Whether to allow HTTP file uploads.file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not; specified).upload_tmp_dir = C:\apache2triad\temp; Maximum allowed size for uploaded files.upload_max_filesize = 2M

60. What are the differences between mysql_fetch_array(), mysql_fetch_object(),mysql_fetch_row()?

Answer:mysql_fetch_array-- Fetch a result row as an associative array, a numeric array, orboth.mysql_fetch_object( resource result )Returns an object with properties that correspond to the fetched row and moves theinternal data pointer ahead. Returns an object with properties that correspond tothe fetched row, or FALSE if there are no more rowsmysql_fetch_row()fetches one row of data from the result associated with thespecified result identifier. The row is returned as an array. Each result column isstored in an array offset, starting at offset 0.

61. Steps for the payment gateway processing?

Ans:An online payment gateway is the interface between your merchant account andyour Web site. The online payment gateway allows you to immediately verify creditcard transactions and authorize funds on a customer's credit card directly fromyour Web site. It then passes the transaction off to your merchant bank forprocessing, commonly referred to as transaction batching


62. List out different arguments in php header function?
Answer:
void
header
( string string [, bool replace [, int http_response_code]])


63. What is the difference between and And which can bepreferable?

Answer:If functionality is same but

64. What are the differences between php3 and php4 versions?

Answer:As has already been mentioned by many PHP4 has native support for sessionsand the much touted XML. While this makes PHP a competitor in theApplication server languages arena, there is another core aspect to PHP4. Itis faster.
PHP3 used to parse line by line, while PHP acts like a compiler. This alongwith the ZEND optimizer makes PHP4 almost always faster than PHP3.I'm not sure about support for COM, it has caught my attention only in PHP4.If it was present in PHP3 I was not aware of it.Plus PHP4 can run as an Apache module, again this could have come in thelate versions of PHP3.

65. What are the differences between include() and include_once()functions?

Answer: include_once() will use the specified file only once. include and require willuse the specified file as many time we want. If include_once() is used before withsame name, it can not done again

66. Explain mysql optimization?

Answer:Optimization is a complex task because ultimately it requires understanding of theentire system. Although it may be possible to perform some local optimizations withlittle knowledge of your system or application, the more optimal you want yoursystem to become, the more you will have to know about it. The most importantfactor in making a system fast is the basic design. You also need to know what kindsof things your system will be doing, and what your bottlenecks are.


67. What is the difference between Reply-to and Return-path in the headers of a mailfunction?

Answer:Reply-to: Reply-to is where to delivery the reply of the mail.Return-path: Return path is when there is a mail delivery failure occurs then whereto delivery the failure notification.


68. Will comparison of string "10" and integer 11 work in PHP?
Answer: Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
69. When are you supposed to use endif to end the conditional statement?
Answer: When the original if was followed by : and then the code block without braces.
70. Explain the ternary conditional operator in PHP?
Answer: Expression preceding the ? is evaluated, if it"s true, then the expression preceding the : is executed,
otherwise, the expression following : is executed.
71. How do I find out the number of parameters passed into function in PHP?
Answer: func_num_args() function returns the number of parameters/arguments passed to a function in PHP.
72. What"s the difference between accessing a class method via -> and via ::?
Answer: In PHP, :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
73. Are objects passed by value or by reference?
Answer: Everything is passed by value. In PHP4 it's true, BUT in PHP5 absolutely not - all objects are passed by reference.
74. How do you call a constructor for a parent class?
Answer: parent::constructor($value)
75. What"s the special meaning of __sleep and __wakeup?
Answer: __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
76. Would you initialize your strings with single quotes or double quotes in PHP?
Answer: Since the data inside the single-quoted string is not parsed for variable substitution, it"s always a
better idea speed-wise to initialize a string with single quotes, unless you specifically need variable
substitution.
77. What"s the difference between htmlentities() and htmlspecialchars()?
Answer: htmlspecialchars only takes care of <, >, single quote ", double quote " and ampersand. htmlentities
translates all occurrences of character sequences that have different meaning in HTML.
78. What"s the difference between md5(), crc32() and sha1() crypto on PHP?
Answer: The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1()
returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

79. What is a Session in PHP?

Answer

A PHP session is no different from a normal session. It can be used to store information on the server for future use. However this storage is temporary and is flushed out when the site is closed. Sessions can start by first creating a session id (unique) for each user.

Syntax : session_start()

80. How can we increase the execution time of a php script?

Answer:Set max_execution_time variable in php.ini file to your desired time in second.