Monday, 6 April 2015

Differences between Public,Private and Protect


Public: When you declare a method (function) or a property (variable) as public, those methods and properties can be accessed by: The same class that declared it. The classes that inherit the above declared class. Any foreign elements outside this class can also access those things. Example: name; // The public variable will be available to the inherited class } } // Inherited class Daddy wants to know Grandpas Name $daddy = new Daddy; echo $daddy->displayGrandPaName(); // Prints 'Mark Henry' // Public variables can also be accessed outside of the class! $outsiderWantstoKnowGrandpasName = new GrandPa; echo $outsiderWantstoKnowGrandpasName->name; // Prints 'Mark Henry' Protected: When you declare a method (function) or a property (variable) as protected, those methods and properties can be accessed by The same class that declared it. The classes that inherit the above declared class. Outsider members cannot access those variables. "Outsiders" in the sense that they are not object instances of the declared class itself. Example: name; } } $daddy = new Daddy; echo $daddy->displayGrandPaName(); // Prints 'Mark Henry' $outsiderWantstoKnowGrandpasName = new GrandPa; echo $outsiderWantstoKnowGrandpasName->name; // Results in a Fatal Error The exact error will be this: PHP Fatal error: Cannot access protected property GrandPa::$name Private: When you declare a method (function) or a property (variable) as private, those methods and properties can be accessed by: The same class that declared it. Outsider members cannot access those variables. Outsiders in the sense that they are not object instances of the declared class itself and even the classes that inherit the declared class. Example: name; } } $daddy = new Daddy; echo $daddy->displayGrandPaName(); // Results in a Notice $outsiderWantstoKnowGrandpasName = new GrandPa; echo $outsiderWantstoKnowGrandpasName->name; // Results in a Fatal Error The exact error messages will be: Notice: Undefined property: Daddy::$name Fatal error: Cannot access private property GrandPa::$name

PHP Built-in Functions

Tuesday, 8 July 2014

PHP interview questions

  1. Which of the following will NOT add john to the users array?

    1. $users[ ] = ‘john’;
    2. Successfully adds john to the array
    3. array_add($users,’john’);
    4. Fails stating Undefined Function array_add()
    5. array_push($users,‘john’);
    6. Successfully adds john to the array
    7. $users ||= ‘john’;
    8. Fails stating Syntax Error
  2. What’s the difference between sort(), asort() and ksort? Under what circumstances would you use each of these?

    1. sort()
      Sorts an array in alphabetical order based on the value of each element. The index keys will also be renumbered 0 to length – 1. This is used primarily on arrays where the indexes/keys do not matter.
    2. asort()
      Like the sort() function, this sorts the array in alphabetical order based on the value of each element, however, unlike the sort() function, all indexes are maintained, thus it will not renumber them, but rather keep them. This is particularly useful with associate arrays.
    3. ksort()
      Sorts an array in alphabetical order by index/key. This is typically used for associate arrays where you want the keys/indexes to be in alphabetical order.
  3. What would the following code print to the browser? Why?

    PHP:
    1. $num = 10;
    2. function multiply(){
    3. $num = $num * 10;
    4. }
    5. multiply();
    6. echo $num; // prints 10 to the screen
    Since the function does not specify to use $num globally either by using global $num; or by $_GLOBALS['num'] instead of $num, the value remains 10.
  4. What is the difference between a reference and a regular variable? How do you pass by reference and why would you want to?

    Reference variables pass the address location of the variable instead of the value. So when the variable is changed in the function, it is also changed in the whole application, as now the address points to the new value.
    Now a regular variable passes by value, so when the value is changed in the function, it has no affect outside the function.
    PHP:
    1. $myVariable = “its’ value”;
    2. Myfunction(&$myVariable); // Pass by Reference Example
    So why would you want to pass by reference? The simple reason, is you want the function to update the value of your variable so even after you are done with the function, the value has been updated accordingly.
  5. What functions can you use to add library code to the currently running script?

    This is another question where the interpretation could completely hit or miss the question. My first thought was class libraries written in PHP, so include(), include_once(), require(), and require_once() came to mind. However, you can also include COM objects and .NET libraries. By utilizing the com_load and the dotnet_load respectively you can incorporate COM objects and .NET libraries into your PHP code, thus anytime you see “library code” in a question, make sure you remember these two functions.
  6. What is the difference between foo() & @foo()?

    foo() executes the function and any parse/syntax/thrown errors will be displayed on the page.
    @foo() will mask any parse/syntax/thrown errors as it executes.
    You will commonly find most applications use @mysql_connect() to hide mysql errors or @mysql_query. However, I feel that approach is significantly flawed as you should never hide errors, rather you should manage them accordingly and if you can, fix them.
  7. How do you debug a PHP application?

    This isn’t something I do often, as it is a pain in the butt to setup in Linux and I have tried numerous debuggers. However, I will point out one that has been getting quite a bit of attention lately.
    PHP – Advanced PHP Debugger or PHP-APD. First you have to install it by running:
    pear install apd
    Once installed, start the trace by placing the following code at the beginning of your script:
    apd_set_pprof_trace();
    Then once you have executed your script, look at the log in apd.dumpdir.
    You can even use the pprofp command to format the data as in:
    pprofp -R /tmp/pprof.22141.0
    For more information see http://us.php.net/manual/en/ref.apd.php
  8. What does === do? What’s an example of something that will give true for ‘==’, but not ‘===’?

    The === operator is used for functions that can return a Boolean false and that may also return a non-Boolean value which evaluates to false. Such functions would be strpos and strrpos.
    I am having a hard time with the second portion, as I am able to come up with scenarios where ‘==’ will be false and ‘===’ would come out true, but it’s hard to think of the opposite. So here is the example I came up with:
    PHP:
    1. if (strpos(“abc”, “a”) == true)
    2. {
    3. // this does not get hit, since “a” is in the 0 index position, it returns false.
    4. }
    5. if (strpos(“abc”, “a”) === true)
    6. {
    7. // this does get hit as the === ensures this is treated as non-boolean.
    8. }
  9. How would you declare a class named “myclass” with no methods or properties?

    PHP:
    1. class myclass
    2. {
    3. }
  10. How would you create an object, which is an instance of “myclass”?

    PHP:
    1. $obj = new myclass();
    It doesn’t get any easier than this.
  11. How do you access and set properties of a class from within the class?

    You use the $this->PropertyName syntax.
    PHP:
    1. class myclass
    2. {
    3. private $propertyName;
    4. public function __construct()
    5. {
    6. $this->propertyName = “value”;
    7. }
    8. }
    1. What is the difference between include, include_once? and require?

      All three allow the script to include another file, be it internal or external depending on if allow_url_fopen is enabled. However, they do have slight differences, which are denoted below.
      1. include()
        The include() function allows you to include a file multiple times within your application and if the file does not exist it will throw a Warning and continue on with your PHP script.
      2. include_once()
        include_once() is like include() except as the name suggests, it will only include the file once during the script execution.
      3. require()
        Like include(), you can request to require a file multiple times, however, if the file does not exist it will throw a Warning that will result in a Fatal Error stopping the PHP script execution.
    2. What function would you use to redirect the browser to a new page?

      1. redir()
        This is not a function in PHP, so it will fail with an error.
      2. header()
        This is the correct function, it allows you to write header data to direct the page to a new location. For example:
        PHP:
      3. location()
        This is not a function in PHP, so it will fail with an error.
      4. redirect()
        This is not a function in PHP, so it will fail with an error.
    3. What function can you use to open a file for reading and writing?

      1. fget()
        This is not a function in PHP, so it will fail with an error.
      2. file_open()
        This is not a function in PHP, so it will fail with an error.
      3. fopen()
        This is the correct function, it allows you to open a file for reading and/or writing. In fact, you have a lot of options, check out php.net for more information.
      4. open_file()
        This is not a function in PHP, so it will fail with an error.
    4. What’s the difference between mysql_fetch_row() and mysql_fetch_array()?

      mysql_fetch_row() returns all of the columns in an array using a 0 based index. The first row would have the index of 0, the second would be 1, and so on. Now another MySQL function in PHP is mysql_fetch_assoc(), which is an associative array. Its’ indexes are the column names. For example, if my query was returning ‘first_name’, ‘last_name’, ‘email’, my indexes in the array would be ‘first_name’, ‘last_name’, and ‘email’. mysql_fetch_array() provides the output of mysql_fetch_assoc and mysql_fetch_row().
    5. What does the following code do? Explain what’s going on there.

      PHP:
      1. $date=’09/25/2008′;
      2. print ereg_replace(“([0-9]+)/([0-9]+)/([0-9]+)”,\\2/\\1/\\3″,$date);
      This code is reformatting the date from MM/DD/YYYY to DD/MM/YYYY. A good friend got me hooked on writing regular expressions like below, so it could be commented much better, granted this is a bit excessive for such a simple regular expression.
      PHP:
      1. // Match 0-9 one or more times then a forward slash
      2. $regExpression = “([0-9]+)/”;
      3. // Match 0-9 one or more times then another forward slash
      4. $regExpression .= “([0-9]+)/”;
      5. // Match 0-9 one or more times yet again.
      6. $regExpression .= “([0-9]+)”;
      Now the \\2/\\1/\\3 denotes the parentheses matches. The first parenthesis matches the month, the second the day, and the third the year.
    6. Given a line of text $string, how would you write a regular expression to strip all the HTML tags from it?

      First of all why would you write a regular expression when a PHP function already exists? See php.net’s strip_tags function. However, considering this is an interview question, I would write it like so:
      PHP:
      1. $stringOfText = “<p>This is a testing</p>”;
      2. $expression = “/<(.*?)>(.*?)<\/(.*?)>/”;
      3. echo preg_replace($expression, \\2″, $stringOfText);
      4. // It was suggested (by Fred) that /(<[^>]*>)/ would work too.
      5. $expression = “/(<[^>]*>)/”;
      6. echo preg_replace($expression, “”, $stringOfText);
    7. What’s the difference between the way PHP and Perl distinguish between arrays and hashes?

      This is why I tell everyone to, “pick the language for the job!” If you only write code in a single language how will you ever answer this question? The question is quite simple. In Perl, you are required to use the @ sign to start all array variable names, for example, @myArray. In PHP, you just continue to use the $ (dollar sign), for example, $myArray.
      Now for hashes in Perl you must start the variable name with the % (percent sign), as in, %myHash. Whereas, in PHP you still use the $ (dollar sign), as in, $myHash.
    8. How can you get round the stateless nature of HTTP using PHP?

      The top two options that are used are sessions and cookies. To access a session, you will need to have session_start() at the top of each page, and then you will use the $_SESSION hash to access and store your session variables. For cookies, you only have to remember one rule. You must use the set_cookie function before any output is started in your PHP script. From then on you can use the $_COOKIE has to access your cookie variables and values.
      There are other methods, but they are not as fool proof and most often than not depend on the IP address of the visitor, which is a very dangerous thing to do.
    9. What does the GD library do?

      This is probably one of my favorite libraries, as it is built into PHP as of version 4.3.0 (I am very happy with myself, I didn’t have to look up the version of PHP this was introduced on php.net). This library allows you to manipulate and display images of various extensions. More often than not, it is used to create thumbnail images. An alternative to GD is ImageMagick, however, unlike GD, this does not come built in to PHP and must be installed on the server by an Administrator.
    10. Name a few ways to output (print) a block of HTML code in PHP?

      Well you can use any of the output statments in PHP, such as, print, echo, and printf. Most individuals use the echo statement as in:
      PHP:
      1. echo “My test string $variable”;
      However, you can also use it like so:
      PHP:
      1. echo <<<OUTPUT
      2. This text is written to the screen as output and this $variable is parsed too. If you wanted you can have <span> HTML tags in here as well.</span> The END; remarks must be on a line of its own, and can‘t contain any extra white space.
      3. END;
    11. Is PHP better than Perl? – Discuss.

      Come on, let’s not start a flame over such a trivial question. As I have stated many times before,
      “Pick the language for the job, do not fit the job into a particular language.”
      Perl in my opinion is great for command line utilities, yes it can be used for the web as well, but its’ real power can be really demonstrated through the command line. Likewise, PHP can be used on the command line too, but I personally feel it’s more powerful on the web. It has a lot more functions built with the web in mind, whereas, Perl seems to have the console in mind.
      Personally, I love both languages. I used Perl a lot in college and I used PHP and Java a lot in college. Unfortunately, my job requires me to use C#, but I spend countless hours at home working in PHP, Perl, Ruby (currently learning), and Java to keep my skills up to date. Many have asked me what happened to C and C++ and do they still fit into my applications from time to time. The answer is primarily ‘No’. Lately all of my development work has been for the web and though C and C++ could be written for the web, they are hardly the language to use for such tasks. Pick the language for the job. If I needed a console application that was meant to show off the performance differences between a quick sort, bubble sort, and a merge sort, give me C/C++! If you want a Photo Gallery, give me PHP or C# (though I personally find .NET languages better for quick GUI applications than web).
    1)What is PHP?
    PHP: Hypertext Preprocessor:PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

    2)How a constant is defined in a PHP script?
    Constants are defined by using the define()directive.PHP constant() is useful if you need to retrieve the value of a constant. PHP Constant value cannot change during the execution of the code. By default constant is case-sensitive
    <html>
    <head>
    <title>My First php Constant Program</title>
    </head>
    <body>
    <?php
    define(“numbers”, 1234);
    define(“TEXT”, “php”);
    echo constant (“numbers”);
    echo constant (“TEXT”);
    ?>
    </body>
    </html>
    output: 1234php
    3)What are the Difference Between strstr() and stristr()?
    This strstr() function is used to return the character from a string from specified position
    Example:
    <html>
    <head>
    <title>My First String strstr Program</title>
    </head>
    <body>
    <?php
    $str=”welcome to php”;
    echo strstr($str,’t’);
    ?>
    </body>
    </html>
    Output: to php
    stristr()function
    This function is same as strstr is used to return the character from a string from specified position,But it is CASE INSENSITIVE
    Example:
    <html>
    <head>
    <title>My First String strIstr Program</title>
    </head>
    <body>
    <?php
    $str=”WELCOME TO PHP”;
    echo stristr($str,’t’);
    ?>
    </body>
    </html>
    output:TO PHP
    4)Differences between Get and post methods in PHP?.
    GET and POST methods are used to send data to the server, both are used to same purpose .But both are some defferences
    GET Method have send limit data like only 2Kb data able to send for request and data show in url,it is not safety.
    POST method unlimited data can we send for request and data not show in url,so POST method is good for send sensetive request
    5)How do I find out the number of parameters passed into function. ?
    func_num_args() function returns the number of parameters passed in.
    6)What is urlencode and urldecode?
    Urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits.
    urlencode Example program:
    <?php
    $arr=urlencode(“20.00%”);
    echo $arr;
    ?>
    Here urlencode(“20.00%”) will return “20.00%25. URL encoded strings are safe to be used as part of URLs.
    urldecode() returns the URL decoded version of the given string.
    urldecode Example Program:
    <?php
    $arr=urldecode(“20.00%”);
    echo $arr;
    ?>
    output:20.00%
    7)How to increase the execution time of a php script?
    To Change max_execution_time variable in php.ini file .By Default time is 30 seconds
    The file path is xampp/php/php.ini
    8)Difference between htmlentities() and htmlspecialchars()?
    htmlentities() – Convert ALL special characters to HTML entities
    htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)
    9)What is the difference between $message and $$message?
    $message is a simple variable whereas $$message is a reference variable.
    Example:
    <?php
    $message = “php”;
    $php= “cms”;
    echo $message;
    echo ‘<br>’;
    echo $$message;
    ?>
    output:
    php
    cms
    10)How To Get the Uploaded File Information in the Receiving Script?
    Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES.
    $_FILES[$fieldName]['name'] – The Original file name on the browser system.
    $_FILES[$fieldName]['type'] – The file type determined by the browser.
    $_FILES[$fieldName]['size'] – The Number of bytes of the file content.
    $_FILES[$fieldName]['error'] – The error code associated with this file upload.
    $_FILES[$fieldName]['tmp_name'] – The temporary filename of the file in which the uploaded file was stored on the server.
    11)What is difference between Array combine() and Array merge()?
    Array_combine(): To Combines the elements of two arrays and Returns the New Array.The new Array keys are the values of First Array values and the new array values are Second array values.
    Array_combine()Example:
    <?php
    $arr=array(10,30,50);
    $arr1=array(45,67,54);
    print_r(array_combine($arr,$arr1));
    ?>
    Output:
    Array
    (
    [10] => 45
    [30] => 67
    [50] => 54
    )
    Array_merge(): merges two or more Arrays as New Array.
    Array_merge() Example:
    <?php
    $arr=array(10,30,50);
    $arr1=array(45,67,54);
    print_r(array_merge($arr,$arr1));
    ?>
    output:
    Array
    (
    [0] => 10
    [1] => 30
    [2] => 50
    [3] => 45
    [4] => 67
    [5] => 54
    )
    12)What is Implode() Function in PHP?
    The implode function is used to “join elements of an array with a string”.
    Example:
    <?php
    $arr=array (“open”,”source”,”cms”);
    echo implode(” “,$arr);
    ?>
    Output: open source cms
    13)what Explode() Function in PHP?
    The explode function is used to “Split a string by a specified string into pieces i.e. it breaks a string into an array”.
    Example:
    <?php
    $str = “Gampa venkateswararao vaidana ballikurava “;
    print_r (explode(” “,$str));
    ?>
    output:
    Array
    (
    [0] => Gampa
    [1] => venkateswararao
    [2] => vaidana
    [3] => ballikurava
    [4] =>
    )
    14)What does a special set of tags do in PHP?
    in PHP special tags <?= and ?> the use of this Tags are The output is displayed directly to the browser.
    15)What is the difference between md5(),crc32() and sha1() in PHP?
    All of these functions generate hashcode from passed string argument.
    The major difference is the length of the hash generated
    crc32() gives 32 bit code
    sha1() gives 128 bit code
    md5() gives 160 bit code
    16)What are the differences between require() and include()?
    Both include() and require() used to include a file ,if the code from a file has already have included,it will not be included again. we have to use this code multiple times .But both are some minor Difference Include() send a Warning message and Script execution will continue ,But Require() send Fatal Error and to stop the execution of the script.
    17)What are the differences between require_once(), include_once?
    require_once() and include_once() are both the functions to include and evaluate the specified file only once.If the specified file is included previous to the present call
    occurrence, it will not be done again.
    18)What is session in php?
    session variable is used to store the information about a user and the information is available in all the pages of one application and it is stored on the server.
    An user sends the first Request to the Server for every new user webserver creates an Unique ID The Request is called as Session_id.Session_id is an unique value generated by the webserver. To start a session by using session_start()
    Starting a PHP Session
    Example:
    <?php
    // this starts the session
    session_start();
    // this sets variables in the session
    $_SESSION['Name']=’Venki’;
    $_SESSION['Qulification']=’MCA’;
    $_SESSION['Age']=27;
    ?>
    Add or access session variables by using the $_SESSION superglobal array.
    How to Retrive Data?
    <?php
    session_start();
    echo “Name = ” $_SESSION["Name"];// retrieve session data
    ?>
    To delete a single session value, you use the unset() function:
    <?php
    session_start();
    unset($_SESSION["Name"]);
    ?>
    How to Destroy the Session?
    <?php
    session_start();
    session_destroy();// terminate the session
    ?>
    19)What is the default session time in php?
    The default session time in php is until closing of browser
    20)What is Cookie and How to Create a Cookie in php?
    Cookie is a piece of information that are stored in the user Browser memory, usually in a temporary folder. Cookies can be useful as they store persistent data you can access from different pages of your Website, but at the same data they are not as secure as data saved in a server
    in PHP, you can both create and retrieve cookie values.
    How to Create a Cookie?
    using The setcookie() function is used to set a cookie.
    Syntax
    setcookie(name, value, expire, path, domain);
    Example
    <?php
    setcookie(“user”, “venki”, time()+3600);
    ?>
    How to a retrieve a cookie value?
    $_COOKIE variable is used to retrieve a cookie value.
    Example:
    <?php
    echo $_COOKIE["user"];// Print a cookie
    print_r($_COOKIE); // view all cookies
    ?>
    How to Accessing a cookie?
    In the following example we use the isset() function to find out if a cookie has been set:
    <?php
    if( isset($_COOKIE['username']) ) //storing the value of the username cookie into a variable
    {
    $username = $_COOKIE['username'];
    }
    ?>
    21)How can you destroy or Delete a Cookie?
    Destroy a cookie by specifying expire time in the past:
    Example: setcookie(’opensource’,’php’,time()-3600); // already expired time
    22)Difference between Persistent Cookie and Temporary cookie?
    A persistent cookie is a cookie which is stored in a cookie file permanently on the
    browser’s computer. By default, cookies are created as temporary cookies which stored
    only in the browser’s memory. When the browser is closed, temporary cookies will be
    erased. You should decide when to use temporary cookies and when to use persistent
    cookies based on their differences:
    · Temporary cookies can not be used for tracking long-term information.
    · Persistent cookies can be used for tracking long-term information.
    · Temporary cookies are safer because no programs other than the browser can
    access them.
    · Persistent cookies are less secure because users can open cookie files see the
    cookie values
    23)Difference Between Cookies and Sessions in php?
    Cookies and sessions both are used to store values or data,But there are some differences a cookie stores the data in your browser memory and a session is stored on the server.
    Cookie data is available in your browser up to expiration date and session data available for the browser run, after closing the browser we will lose the session information.
    Cookies can only store string data,but session stored any type of data.we could be save cookie for future reference, but session couldn’t. When users close their browser, they also lost the session.
    Cookies are unsecured,but sessions are highly Secured.
    You lose all the session data once you close your browser, as every time you re-open your browser, a new session starts for any website.
    Cookies stores some information like the username, last visited Web pages etc. So that when the customer visits the same site again, he may have the same environment set for him. You can store almost anything in a browser cookie.when you check the ‘Remember Password’ link on any website, a cookie is set in your browser memory, which exists there in the browser until manually deleted. So, when you visit the same website again, you don’t have to re-login.
    The trouble is that a user can block cookies or delete them at any time. If, for example, your website’s shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.
    24)How to connet mysql database with PHP ?
    $con = mysql_connect(“localhost”, “username”, “password”);
    Example:
    <?php
    if($con=mysql_connect(“localhost”,”root”,””))
    echo “connected”;
    else
    echo “not connected”;
    if(mysql_query(“create Database emp”,$con))
    echo “Database Created”;
    else
    echo “Database not Created”;
    ?>
    output:
    connectedDatabase Created
    25)What is the function mysql_pconnect() usefull for?
    mysql_pconnect() ensure a persistent connection to the database, it means that the connection do not close when the the PHP script ends.
    26)Different Types of Tables in Mysql?
    There are Five Types Tables in Mysql
    1)INNODB
    2)MYISAM
    3)MERGE
    4)HEAP
    5)ISAM
    27)What is the Difference between INNODB and MYISAM?
    The main difference between MyISAM and InnoDB is that InnoDB supports transaction
    InnoDB supports some newer features: Transactions, row-level locking, foreign keys
    MYISAM:
    1. MYISAM supports Table-level Locking
    2. MyISAM designed for need of speed
    3. MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
    4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
    5. MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.
    INNODB:
    1. InnoDB supports Row-level Locking
    2. InnoDB designed for maximum performance when processing high volume of data
    3. InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
    4. InnoDB stores its tables and indexes in a tablespace
    5. InnoDB supports transaction. You can commit and rollback with InnoDB
    28) What is the difference between mysql_fetch_object() and mysql_fetch_array()?
    The mysql_fetch_object() function collects the first single matching record
    mysql_fetch_array() collects all matching records from the table in an array.
    28)How many ways we can retrieve the date in result set of mysql using php?
    The result set can be handled using 4 ways
    1. mysql_fetch_row.
    2. mysql_fetch_array
    3. mysql_fetch_object
    4. mysql_fetch_assoc
    29)What are the differences between DROP a table and TRUNCATE a table?
    DROP TABLE table_name – This will delete the table and its data.
    TRUNCATE TABLE table_name – This will delete the data of the table, but not the table definition.
    30)What is the maximum length of a table name, a database name, or a field name in MySQL?
    Database name: 64 characters
    Table name: 64 characters
    Column name: 64 characters
    31)What is the difference between CHAR and VARCHAR data types?
    CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column.
    VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column.
    32)How can we know that a session is started or not?
    A session starts by using session_start() function.

About these ads

Saturday, 5 July 2014

r Mode r+ Mode w Mode w+ Mode a Mode a+ Mode
  1. Open the file for read mode only.
  2. File pointer places at beginning of the file.
  3. It never creates a new file if file doesn't exists & doesn't truncates content of the existed file.
  1. Open the file for read and write mode. 
  2. File pointer places at beginning  of the file.
  3. It never creates a new file if file doesn't exists & doesn't truncates content of the existed file. .
  1. Open the file for write mode. 
  2. File pointer places at beginning of the file.
  3. It creates a new file if file doesn't exists & truncates the content of file to 0 length.
  1. Open the file for  read and write mode. 
  2. File pointer places at beginning of the file.
  3. It creates a new file if file doesn't exists & truncates the content of the file to 0 length.
  1. Open the  file for  write mode only. 
  2. File pointer places at  ending of the file.
  3. It creates a new file if file doesn't exists & doesn't truncates existed file content  to 0 length.
  1. Open the file for read and write mode. 
  2. File pointer places at ending of the file.
  3. It creates a new file if file doesn't exists & doesn't truncates existed file content  to 0 length.

Friday, 20 June 2014

What are the differences between GET and POST methods?


  • GET & POST are HTTP request methods(is a request/response protocal, whenever you fetches a file or a image from a web server it dose so using - that's Hypertext Transfer protocal  ).
  • These methods  used to send browser client information to web server.