In PHP what is the difference between a Class and an Interface?
Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.
What is MVC?
Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it.
MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job.
Model - Usually contains data access code and all of you business logic code.
View - Contains markup/design code, generally html,xml, json.
Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.
MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job.
Model - Usually contains data access code and all of you business logic code.
View - Contains markup/design code, generally html,xml, json.
Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.
What does ob_start do?
Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.
I want to share this great php utility: the output buffering, it is sometimes very usefull. So what it does ?
The PHP output buffering will save all the server outputs ( html and php prints) to a string variable.
So to start buffering, use ob_start(); this will keep saved any output.
Then you use $variable = ob_get_clean(); to stop buffering, and copy the buffer content to the variable.
Here are few samples of the use of ob_start() and ob_get_clean()
<?php ob_start(); //Turn on output buffering ?>
Hello world, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>
<?php $var = ob_get_clean(); //copy current buffer contents into $message variable and delete current output buffer ?>
Now the content of the variable $var should be:
Hello word, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>
Another example (with php outputs buffered)
<?php ob_start(); ?>
Hello world, <?php echo "My Website"; ?>
Thank you.
<?php $var = ob_get_clean(); ?>
And this will be the content of $var:
What is the difference between CHAR AND VARCHAR?
The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved.
The length of a CHAR column is fixed to the length that you declare when you create the table.
The length can be any value between 1 and 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.
The PHP output buffering will save all the server outputs ( html and php prints) to a string variable.
So to start buffering, use ob_start(); this will keep saved any output.
Then you use $variable = ob_get_clean(); to stop buffering, and copy the buffer content to the variable.
Here are few samples of the use of ob_start() and ob_get_clean()
<?php ob_start(); //Turn on output buffering ?>
Hello world, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>
<?php $var = ob_get_clean(); //copy current buffer contents into $message variable and delete current output buffer ?>
Now the content of the variable $var should be:
Hello word, <a href="http://www.blogger.com/myotherpage.php">link</a>
<div class="style">Content</div>
Another example (with php outputs buffered)
<?php ob_start(); ?>
Hello world, <?php echo "My Website"; ?>
Thank you.
<?php $var = ob_get_clean(); ?>
And this will be the content of $var:
Hello world, My Website
Thank you
Thank you
What is the difference between CHAR AND VARCHAR?
The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved.
The length of a CHAR column is fixed to the length that you declare when you create the table.
The length can be any value between 1 and 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.
How do you get the month from a timestamp?
SELECT MONTH(january_timestamp) from tablename;
Where MyISAM table is stored?
Each MyISAM table is stored on disk in three files.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension
SELECT MONTH(january_timestamp) from tablename;
Where MyISAM table is stored?
Each MyISAM table is stored on disk in three files.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension
How to get size & type of uploaded image?
list($width, $height, $type) = getimagesize($_FILES['photo_file']['tmp_name']);
list($width, $height, $type) = getimagesize($_FILES['photo_file']['tmp_name']);
How can we submit a form without a submit button?
The main idea behind this is to use Java script submit( function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit( ) method to onclick, onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites.
How can we create a database using PHP and MySQL?
We can create MySQL database with the use of
mysql_create_db(“Database Name”);
What are the different tables present in MySQL?
Total types of tables we can create
. MyISAM
. Heap
. Merge
. INNO DB
. ISAM
. MyISAM
. Heap
. Merge
. INNO DB
. ISAM
MyISAM is the default storage engine as of MySQL . and as a result if we do not specify the table name explicitly it will be assigned to the default engine.