Thursday, January 22, 2009

What is differenc between mysql_connect and mysql_pconnect?

mysql_connect() and mysql_pconnect() both are working for database connection, but some different are as follows:

  • When we are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request, But in case of mysql_pconnect() function, First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the connection will remain open for future use (mysql_close() will not close connection established by mysql_pconnect()).
  • mysql_pconncet() is useful when you have a lot of traffic on your site. At that time for every request it will not open a connection but will take it from the pool. This will increase the efficiency of your site. In general use mysql_connect() is best. In mysql_pconnect(), ‘p’ stands for persistence connection.


What is the difference between echo and print statement?

  • echo() can take multiple expressions, print cannot
    take multiple expressions.

  • echo has the slight performance advantage because
    it doesn't have a return value. So, echo is a little bit faster but print
    return a integer value of 1.


  • <?php

    if(print('something'))

    // makes sense, while

    if(echo('something'))

    // doesn’t

    ?>

    PHP Interview Question?

    1. How I will check that user is logged in or not?
    2. I want to make it a function and I want to use it in each page and after login I want to go in current page?
    3. How do we know browser properties?
    4. If you have to work with dates in the following format: “Tuesday, February 14, 2006 @ 10:39 am”, how can you convert them to another format, that is easier to use?
    5. What is difference between require_once(), require(), include()?

    Tuesday, January 20, 2009

    PHP Interview Question

    1. How can I maintain the count of how many persons have hit my site?

    • Create a text file to store the no of value of user hit.
    • At the first time the file count variable is 0 then every time when the form is load and user click on that form at that time we open the file and increment the counter variable.
    • Then close the file in this way we can find that how many time the the page is hitted by the user
    • The best way is to use session variables. So that whenever a user hits web-page, we can increment the counter in the session variable set for number of users.
    • In your database maintain separate table visitor detail, for example you have user_detail table filed is count_user in your index file put on the particular code: mysql_query("update user_detail set count _visitor+1"); Whenever index file opened so that query will execute


    1. What is difference between mysql_fetch_array(), mysql_fetch_row() and mysql_fetch_object()?
    • mysql_fetch_array():- Fetch a result row as an associative array, a numeric array, or both by default it fetches both.

    • mysql_fetch_row() :- Get a result row as an numeric array.

    • mysql_fetch_object :- Fetch a result row as an object.


    1. How I can make a chat page in php in simple
    • Create a .txt file.
    • Open it in write mode then write something in message box that will write in that file.
    • Another user also open that file and write the file with the message box.
    • Also open the file in read mod in side window to see what the other user is written.
    • By this way we can make simple chat file with php.


    1. How I can get IP address of the usr?