Interview Question
1. How to reverse String, withought using string function?
$str = 'Hello World';
for($i=strlen($str);$i>=0;$i--) {
$nstr .=$str{$i};
}
echo $nstr;
-----------
Word to word reverse
$str = 'My name is James';
$str_arr = explode(' ',$str);
$i=0;
for($i=(count($str_arr)-1);$i>=0;$i--){
echo $str_arr[$i].' ';
}
-----------------------------------
2. Write code for pandoriam numbers(Fibonacci Sequence) like as 0,1,1,2,3,5,8......
<?php
$first = 0; $second =1;
function fabo($n,$first,$second){
$fab=array($first,$second);
for($i=1;$i<$n;$i++){
$fab[] = $fab[$i] + $fab[$i-1];
}
return $fab;
}
$result = fabo(10,$first,$second);
echo '<pre>';
print_r($result);
?>
---------------------------
3. What is clusstering,indexing in mysql
4. Diffrence bw abstarct class and interfaces
5. Put method in API
To use POST to create resources, or use PUT to update resources.
PUT is idempotent, while POST is not.
6. What you can understand in threading in php/mysql.
PHP
To speed up the execution of multiple tasks, it makes sense to split the work over multiple threads, each performing a smaller task. On a multi-core or on multiple processors, this will mean that multiple processors can do a part of the work that needs to be done, at the same time, rather than completing everything sequentially, in 1 single thread of execution.
pecl install pthreads
Mysql
MySQL uses locking (table-level for MyISAM or row-level for InnoDB), which does not allow 2 processes (2 calls to the script) to modify the same row. So the table won't crash*, but it's possible that MySQL can't handle the number of request in reasanoble time and the requests will wait. You should always optimize your queries to be as fast as possible.
*MyISAM could crash on insert/update intensive applications, but it has automatic recovery. However keep in mind that in such application, InnoDB has far better performance
---
7. Type of curl request, ashync and shncrocus curl request.
8.routes in ci.
6. cleaning through routes in CI.
10. OOPS concept in php.
11. Features of PHP
12. Magic Methods
13. Diffrence bw vednor and libraries.
The “vendors” folder in the “app” folder is for application-specific third-party libraries whereas the other “vendors” folder is for libraries you want to use in multiple applications.
14. In which condition we can't pass parameter on the function at the time of function declaration.
15.what we need to activate/set https in any website.
16. How can we check any value in associative array.
17. What is put method and diffrence bw put and post.
18. What is namespace?
19. Get the manager who have not any manager if we have 2 fields empl_id and manager_id in a table.
select * from tablename where manager_id = ""
20. Swap 2 varible values $a,$b withought using third variable.
<?php
$a = 5; $b =10;
$b = $a +$b;
echo $a = $b - $a;
echo $b = $b - $a;
?>
21. Do the sorting of array using single for loop.
<?php
$array = array('1','2','4','3','8','7','10','11');
$c = count($array);
for($i=0;$i<$c;$i++)
{
if($array[$i] > $array[$i+1]) {
$temp = $array[$i+1];
$array[$i+1]=$array[$i];
$array[$i]=$temp;
}
}
echo "Sorted Array is: ";
echo "<br /><pre>";
print_r($array);
?>
22. What are design pattern in PHP, please explain with example.
23. What is polymosphirsm explain with example.
24. What is indexing exlain in details.
25. Can we create multiple primary in a table?
No
26. What is unique key?
27. What is candidate and foreign key?
Candidate Key – A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.
Primary Key – A Primary Key is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key.
---
28. How can we copy singlot class object in another variable?
Object Cloning $copy_of_object = clone $object
Objects and references $a = &$b, copy $a = $b
Yes, that's normal. Objects are always "assigned" by reference in PHP5. To actually make a copy of an object, you need to clone it.
---
29. Explain github and git n details.
29.1 What is the difference between Git and GitHub?
Git is a version control system; think of it as a series of snapshots (commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.
GitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.
29.2 Is Git saving every repository locally (in the user's machine) and in GitHub?
No, it's only local. You can decide to push (publish) some branches on GitHub.
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
Yes, Git runs local if you don't use GitHub. An alternative to using GitHub could be running Git on files hosted on Dropbox, but GitHub is a more streamlined service as it was made especially for Git.
----
30. Can we define multiple unique key in a table.
Yes
31. What is normalization, can you explain in details.
32. How can we get diffrence-2 format of ajax response in php with single request?
$.ajax({
type: "POST",
url: "your url goes here",
data: "data to be sent",
success: function(response, status, xhr){
var ct = xhr.getResponseHeader("content-type") || "";
if (ct.indexOf('html') > -1) {
//do something
}
if (ct.indexOf('json') > -1) {
// handle json here
}
}
});
----
You can simply use javascript's easy method to check the type
if(typeof response=="object")
{
// Response is javascript object
}
else
{
// Response is HTML
}
---
The answers above didnt work for me so I came up with this solution:
success: function(data, textStatus , xhr) {
if(xhr.responseXML.contentType == "text/html") {
//do something with html
}
else if(xhr.responseXML.contentType == "application/json") {
//do something with json
}}
---
response is in xml
if (xmldoc.responseXML) {
// Is valid XML
} else {
// Is not XML, or invalid XML
}
---------------------
33. How can we diffrenciate ajax and simple response after click on any url?
As of Codeigniter 2.0 it is prefered to use $this->input->is_ajax_request()
OR
if (strtolower(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest') {
// I'm AJAX!
}
---
34. What is left join,inner join,inner left join, outer left join.
35. How can we check and debug the execution time of any query.
$start = microtime(true);
$stmt->execute();
$end = microtime(true);
echo "This query took " . ($end - $start) . " milliseconds.";
---
$db->query('set profiling=1'); //optional if profiling is already enabled
$db->query($_POST['query']);
$stmt = $db->query('show profiles');
$db->query('set profiling=0'); //optional as well
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
---
mysql logs
---
34. What is view table how can we create?
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.
SQL CREATE VIEW Syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
----
36. Explain transaction in details.
37. Where session store, how can we check session value, gave the file name where sesson store?
38. If any one change the value of session id what will happen?
It will create new session id
39. If i have delete the cookie will the session work or what happen?
It will not work
40. If i have disable the cookie how the session will work.?
There are two methods to propagate a session id:
Cookies
URL parameter
<a href="nextpage.php?<?php echo htmlspecialchars(SID); ?>">click here</a>.
Printing the SID, like shown above, is not necessary if --enable-trans-sid was used to compile PHP.
41. Get the dob of all employee whome date of birth will in next week from the table of employee having 3 colum name,id and dob.
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;
42. How can we use multiple model in cakephp.
43. What is mime type in mysql table?
They are used as part of the advanced features of phpMyAdmin. The MIME Type is the file type for the contents of the file and the transformation is how it is 'altered' for presentation.
e.g. If you have an image stored in a table and you tried to view it in phpmyadmin it would just show a bunch of garbage text but if you set the correct MIME type for the image and the correct transformation it could instead show the picture.
44. is the PHP support mime table for sending mail?
45. What is browser transformation?
They are used as part of the advanced features of phpMyAdmin. The MIME Type is the file type for the contents of the file and the transformation is how it is 'altered' for presentation.
e.g. If you have an image stored in a table and you tried to view it in phpmyadmin it would just show a bunch of garbage text but if you set the correct MIME type for the image and the correct transformation it could instead show the picture.
46. Write sql query to export table, write sql query to export all data in txt or sql file
mysql -e "select * from myTable" -u myuser -pxxxxxxxx mydatabase > mydumpfile.txt
47. Write sql query to import data from sql or txt file
mysql -u username -p databasename tableName < path/sqlfile.sql
48. #1062 - Duplicate entry '127' for tinyint
49. With which PHP function we can create <br/> html tag for new line?
nl2br()
50. We can't define more than one primary key in a table.
51. We can define muliple unique in table.
52. Unique/Primary key cant duplicate.
53. If we define null to unique key then it will duplicate for any colum.
54. We can track our sql.
55. If we set default null to any interger type of value it will take 0 and varchar type of value take NULL.
56. Primary key can't duplicate eighter we set default null.
57. Mysql_close will stop all the mysql query after that cause for run any mysql query connection need to start.
58. Mysql_insert_id return last primary key inserted in table.
59. Mysql_affected_rows function will return number of affected rows by any query if query fail it will return -1;
60 Headers used to download file php
65 Design patterns
http://www.techflirt.com/php-design-patterns-examples/
66 Late static binding and Singleton pattern
http://www.techflirt.com/tutorials/oop-in-php/late-static-binding.html
67. Composition vs Inheritance
1. How to reverse String, withought using string function?
$str = 'Hello World';
for($i=strlen($str);$i>=0;$i--) {
$nstr .=$str{$i};
}
echo $nstr;
-----------
Word to word reverse
$str = 'My name is James';
$str_arr = explode(' ',$str);
$i=0;
for($i=(count($str_arr)-1);$i>=0;$i--){
echo $str_arr[$i].' ';
}
-----------------------------------
2. Write code for pandoriam numbers(Fibonacci Sequence) like as 0,1,1,2,3,5,8......
<?php
$first = 0; $second =1;
function fabo($n,$first,$second){
$fab=array($first,$second);
for($i=1;$i<$n;$i++){
$fab[] = $fab[$i] + $fab[$i-1];
}
return $fab;
}
$result = fabo(10,$first,$second);
echo '<pre>';
print_r($result);
?>
---------------------------
3. What is clusstering,indexing in mysql
4. Diffrence bw abstarct class and interfaces
5. Put method in API
To use POST to create resources, or use PUT to update resources.
PUT is idempotent, while POST is not.
6. What you can understand in threading in php/mysql.
PHP
To speed up the execution of multiple tasks, it makes sense to split the work over multiple threads, each performing a smaller task. On a multi-core or on multiple processors, this will mean that multiple processors can do a part of the work that needs to be done, at the same time, rather than completing everything sequentially, in 1 single thread of execution.
pecl install pthreads
Mysql
MySQL uses locking (table-level for MyISAM or row-level for InnoDB), which does not allow 2 processes (2 calls to the script) to modify the same row. So the table won't crash*, but it's possible that MySQL can't handle the number of request in reasanoble time and the requests will wait. You should always optimize your queries to be as fast as possible.
*MyISAM could crash on insert/update intensive applications, but it has automatic recovery. However keep in mind that in such application, InnoDB has far better performance
---
7. Type of curl request, ashync and shncrocus curl request.
8.routes in ci.
6. cleaning through routes in CI.
10. OOPS concept in php.
11. Features of PHP
12. Magic Methods
13. Diffrence bw vednor and libraries.
The “vendors” folder in the “app” folder is for application-specific third-party libraries whereas the other “vendors” folder is for libraries you want to use in multiple applications.
14. In which condition we can't pass parameter on the function at the time of function declaration.
15.what we need to activate/set https in any website.
16. How can we check any value in associative array.
17. What is put method and diffrence bw put and post.
18. What is namespace?
19. Get the manager who have not any manager if we have 2 fields empl_id and manager_id in a table.
select * from tablename where manager_id = ""
20. Swap 2 varible values $a,$b withought using third variable.
<?php
$a = 5; $b =10;
$b = $a +$b;
echo $a = $b - $a;
echo $b = $b - $a;
?>
21. Do the sorting of array using single for loop.
<?php
$array = array('1','2','4','3','8','7','10','11');
$c = count($array);
for($i=0;$i<$c;$i++)
{
if($array[$i] > $array[$i+1]) {
$temp = $array[$i+1];
$array[$i+1]=$array[$i];
$array[$i]=$temp;
}
}
echo "Sorted Array is: ";
echo "<br /><pre>";
print_r($array);
?>
22. What are design pattern in PHP, please explain with example.
23. What is polymosphirsm explain with example.
24. What is indexing exlain in details.
25. Can we create multiple primary in a table?
No
26. What is unique key?
27. What is candidate and foreign key?
Candidate Key – A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.
Primary Key – A Primary Key is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key.
---
28. How can we copy singlot class object in another variable?
Object Cloning $copy_of_object = clone $object
Objects and references $a = &$b, copy $a = $b
Yes, that's normal. Objects are always "assigned" by reference in PHP5. To actually make a copy of an object, you need to clone it.
---
29. Explain github and git n details.
29.1 What is the difference between Git and GitHub?
Git is a version control system; think of it as a series of snapshots (commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.
GitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.
29.2 Is Git saving every repository locally (in the user's machine) and in GitHub?
No, it's only local. You can decide to push (publish) some branches on GitHub.
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
Yes, Git runs local if you don't use GitHub. An alternative to using GitHub could be running Git on files hosted on Dropbox, but GitHub is a more streamlined service as it was made especially for Git.
----
30. Can we define multiple unique key in a table.
Yes
31. What is normalization, can you explain in details.
32. How can we get diffrence-2 format of ajax response in php with single request?
$.ajax({
type: "POST",
url: "your url goes here",
data: "data to be sent",
success: function(response, status, xhr){
var ct = xhr.getResponseHeader("content-type") || "";
if (ct.indexOf('html') > -1) {
//do something
}
if (ct.indexOf('json') > -1) {
// handle json here
}
}
});
----
You can simply use javascript's easy method to check the type
if(typeof response=="object")
{
// Response is javascript object
}
else
{
// Response is HTML
}
---
The answers above didnt work for me so I came up with this solution:
success: function(data, textStatus , xhr) {
if(xhr.responseXML.contentType == "text/html") {
//do something with html
}
else if(xhr.responseXML.contentType == "application/json") {
//do something with json
}}
---
response is in xml
if (xmldoc.responseXML) {
// Is valid XML
} else {
// Is not XML, or invalid XML
}
---------------------
33. How can we diffrenciate ajax and simple response after click on any url?
As of Codeigniter 2.0 it is prefered to use $this->input->is_ajax_request()
OR
if (strtolower(filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest') {
// I'm AJAX!
}
---
34. What is left join,inner join,inner left join, outer left join.
35. How can we check and debug the execution time of any query.
$start = microtime(true);
$stmt->execute();
$end = microtime(true);
echo "This query took " . ($end - $start) . " milliseconds.";
---
$db->query('set profiling=1'); //optional if profiling is already enabled
$db->query($_POST['query']);
$stmt = $db->query('show profiles');
$db->query('set profiling=0'); //optional as well
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
---
mysql logs
---
34. What is view table how can we create?
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.
SQL CREATE VIEW Syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
----
36. Explain transaction in details.
37. Where session store, how can we check session value, gave the file name where sesson store?
38. If any one change the value of session id what will happen?
It will create new session id
39. If i have delete the cookie will the session work or what happen?
It will not work
40. If i have disable the cookie how the session will work.?
There are two methods to propagate a session id:
Cookies
URL parameter
<a href="nextpage.php?<?php echo htmlspecialchars(SID); ?>">click here</a>.
Printing the SID, like shown above, is not necessary if --enable-trans-sid was used to compile PHP.
41. Get the dob of all employee whome date of birth will in next week from the table of employee having 3 colum name,id and dob.
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;
42. How can we use multiple model in cakephp.
43. What is mime type in mysql table?
They are used as part of the advanced features of phpMyAdmin. The MIME Type is the file type for the contents of the file and the transformation is how it is 'altered' for presentation.
e.g. If you have an image stored in a table and you tried to view it in phpmyadmin it would just show a bunch of garbage text but if you set the correct MIME type for the image and the correct transformation it could instead show the picture.
44. is the PHP support mime table for sending mail?
45. What is browser transformation?
They are used as part of the advanced features of phpMyAdmin. The MIME Type is the file type for the contents of the file and the transformation is how it is 'altered' for presentation.
e.g. If you have an image stored in a table and you tried to view it in phpmyadmin it would just show a bunch of garbage text but if you set the correct MIME type for the image and the correct transformation it could instead show the picture.
46. Write sql query to export table, write sql query to export all data in txt or sql file
mysql -e "select * from myTable" -u myuser -pxxxxxxxx mydatabase > mydumpfile.txt
47. Write sql query to import data from sql or txt file
mysql -u username -p databasename tableName < path/sqlfile.sql
48. #1062 - Duplicate entry '127' for tinyint
49. With which PHP function we can create <br/> html tag for new line?
nl2br()
50. We can't define more than one primary key in a table.
51. We can define muliple unique in table.
52. Unique/Primary key cant duplicate.
53. If we define null to unique key then it will duplicate for any colum.
54. We can track our sql.
55. If we set default null to any interger type of value it will take 0 and varchar type of value take NULL.
56. Primary key can't duplicate eighter we set default null.
57. Mysql_close will stop all the mysql query after that cause for run any mysql query connection need to start.
58. Mysql_insert_id return last primary key inserted in table.
59. Mysql_affected_rows function will return number of affected rows by any query if query fail it will return -1;
60 Headers used to download file php
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
61 Differences between Stored Procedures and Functions in MYSQL
Stored Procedure can return zero or n values whereas function can return one value which is mandatory.
Functions can be called from procedure whereas procedures cannot be called from function.
Procedures can have input/output parameters for it whereas functions can have only input parameters.
Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
We can go for transaction management in procedure whereas we can't go in function.
Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
62. mysql queries http://www.w3resource.com/mysql-exercises/
65 Design patterns
http://www.techflirt.com/php-design-patterns-examples/
66 Late static binding and Singleton pattern
http://www.techflirt.com/tutorials/oop-in-php/late-static-binding.html
67. Composition vs Inheritance
Composition means
HAS AInheritance means IS AExample: Car has a Engine and Car is a Automobile
In programming this is represented as:
|
No comments:
Post a Comment