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]
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, and indexes 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).
When you want to show some part of a text displayed on an HTML page in red font color, what different possibilities are there to do this? What are the advantages/disadvantages of these methods?
Answer: Using Html font color tag: I am Amin Using tag in CSS: STRONG {color:red} So when we use the tag:
I am Amin about this. Using Class in CSS: .colorclass { color:#FF3399; font-weight:900; } I am Amin If we use html the modification will be trouble some because we have to change the code of the page. But when we use CSS then it will be easy to change the CSS file and we can get the desired out put.
When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?
Answer: When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder. A page that Internet Explorer is browsing is not cached until half of the 64 KB > buffer is filled. Usually, metatags are inserted in the header section of an > HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML ocument. For example:
What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
Answer: There is at least 3 ways to logon to a remote server: Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.
Please give a regular _expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag.
Example: The regular _expression should match the tag
A select query over a large table runs very slow because of the growing number of entries in that table. What different measures could be taken to improve speed?
Answer: In general, when you want to make a slow SELECT … WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT. Some general tips for speeding up queries on MyISAM tables: A: To help MySQL better optimize queries, use ANALYZE TABLE or run myisamchk –analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL uses this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk –description –verbose shows index distribution information.
A company wants to store their invoices in a database. They already have their customers and articles in that database. Both customer and article are each identified by an unique integer value. Please create the SQL statements for creating the necessary table(s) for storing the invoices in a MySQL database.An invoice should hold information like invoice number, customer, date, article(s) and quantity etc.
Ans:CREATE TABLE invoice ( id int(11) NOT NULL default ‘0′, invoceNo int(11) NOT NULL default ‘0′, customer_id varchar(20) NOT NULL default ‘0′, article_id varchar(20) NOT NULL default ‘0′, date varchar(20) NOT NULL default ‘0′, quantity int(11) NOT NULL default ‘0′, PRIMARY KEY (id) ) TYPE=MyISAM;
For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number “1234″. The query should be able to run under a MySQL 4.0 database.
Answer: Select invoceNo from invoice where article_id=1234;
Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.
Answer:
What is meant by MIME?
Answer: Multipurpose Internet Mail Extensions. WWW’s ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. …
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 users A system for code distribution and package maintenance A standard style for code written in PHP The PHP Foundation Classes (PFC), The PHP Extension Community Library (PECL), A web site, mailing lists and download mirrors to support the PHP/PEAR community PEAR 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 people have joined the project since then. http://pear.php.net/manual/en/introduction.php
How can I use the COM components in php?
Answer: The COM class provides a framework to integrate (D)COM components into your PHP scripts. string COM::COM ( string module_name [, string server_name [, int codepage]]) COM class constructor. Parameters:
module_name name or class-id of the requested component. server_name name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com.allow_dcom has to be set to TRUE in php.ini. codepage specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.
Usage:
Version}\n”; //bring it to front $word->Visible = 1; //open an empty document $word->Documents->Add(); //do some weird stuff $word->Selection->TypeText(”This is a test…”); $word->Documents[1]->SaveAs(”Useless test.doc”); //closing word $word->Quit(); //free the object $word->Release(); $word = null; ?>
How many ways we can give the output to a browser?
Answer: HTML output PHP, ASP, JSP, Servlet Function Script Language output Function Different Type of embedded Package to output to a browser
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.then we write session_register().
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
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
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, or both. mysql_fetch_object ( resource result ) Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0
How can I set a cron and how can I execute it in Unix, Linux, and windows?
Answer: Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time. The easiest way to use crontab is via the crontab command.
# crontab –e This command ‘edits’ the crontab. Upon employing this command, you will be able to enter the commands that you wish to run. My version of Linux uses the text editor vi. You can find information on using vi here. The syntax of this file is very important – if you get it wrong, your crontab will not function properly. The syntax of the file should be as follows: minutes hours day_of_month month day_of_week command All the variables, with the exception of the command itself, are numerical constants. In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows: Minutes: 0-59 Hours: 0-23 Day_of_month: 1-31 Month: 1-12 Weekday: 0-6 We can also include multiple values for each entry, simply by separating each value with a comma. command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file. So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line: 15 8 * * 2 /path/to/scriptname This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content. For our purposes, I’ll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell. If you’re using an RPM-based system (e.g. Redhat or Mandrake), type the following: # wget –help If you are greeted with a wget package identification, it is installed in your system.
You could execute the PHP by invoking wget on the URL to the page, like so: # wget http://www.example.com/file.php Now, let’s go back to the mailstock.php file we created in the first part of this article. We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I’m located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value. This is what my crontab will look like: 0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php
Steps for the payment gateway processing?
Ans: An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer’s credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching
How many ways I can register the variables into session?
Answer:session_register(); $_SESSION[]; $HTTP_SESSION_VARS[];
Explain different types of errors in php (i.e. arguments in error reporting function)?
Answer: Three are three types of errors:
1. Notices: These are trivial, non-critical errors that PHP encounters while executing 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() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. 3. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.
How many ways I can redirect a php page?
Answer; Here are the possible ways of php page redirection.
Using Java script: if (!headers_sent())
header(’Location: ‘.$filename);
else { echo echo echo echo echo echo } } ‘‘; ‘‘; ‘<meta http-equiv=”refresh” content=”0;url=’.$filename.’” />’; ‘ ‘;
redirect(’http://maosjb.com’); ?> Using php function: Header(”Location:http://maosjb.com “);
List out different arguments in php header function?
Answer: void header ( string string [, bool replace [, int http_response_code]])
What type of headers have to add in the mail function in which file a attached?
Answer: $boundary = ‘—–=’ . md5( uniqid ( rand() ) ); $headers = “From: \”Me\”\n”; $headers .= “MIME-Version: 1.0\n”; $headers .= “Content-Type: multipart/mixed; boundary=\”$boundary\”";
What is the difference between and And which can be preferable?
Answer: If functionality is same but
What are the differences between php3 and php4 versions?
Answer: As has already been mentioned by many PHP4 has native support for sessions and the much touted XML. While this makes PHP a competitor in the Application server languages arena, there is another core aspect to PHP4. It is faster.
PHP3 used to parse line by line, while PHP acts like a compiler. This along with 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 the late versions of PHP3.
What are the differences between include() and include_once() functions?
Answer: include_once() will use the specified file only once. include and require will use the specified file as many time we want. If include_once() is used before with same name, it can not done again
Describe the importance of DATA BASE ABSTRACTION LAYERS in php and database connection?
Answer: Please visit to know about Database abstraction layers http://www.oracle.com/technology/pub/articles/deployphp/schlitt_deployphp.html
Explain mysql optimization?
Answer: Optimization is a complex task because ultimately it requires understanding of the entire system. Although it may be possible to perform some local optimizations with little knowledge of your system or application, the more optimal you want your system to become, the more you will have to know about it. The most important factor in making a system fast is the basic design. You also need to know what kinds of things your system will be doing, and what your bottlenecks are. See more at: http://www.serveriai.lt/manual/mysql/manual_MySQL_Optimisation.html
What is the difference between using copy() and move() function in php file uploading?
Answer:copy ( string source, string dest) Makes a copy of the file source to dest. Returns TRUE on success or FALSE on failure. Usage:
\n”; } ?>
move_uploaded_file ( string filename, string destination)
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination. If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
What is the difference between Reply-to and Return-path in the headers of a mail function?
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 where to delivery the failure notification.
Explain about Type Juggling in php?
Answer: PHP does not require (or support) explicit type definition in variable declaration; a variable’s type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer. An example of PHP’s automatic type conversion is the addition operator ‘+’. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.
$foo += 2; // $foo is now an integer (2) $foo = $foo + 1.3; // $foo is now a float (3.3) $foo = 5 + “10 Little Piggies”; // $foo is integer (15) $foo = 5 + “10 Small Pigs”; // $foo is integer (15) ?> If the last two examples above seem odd, see String conversion to numbers. If you wish to change the type of a variable, see settype(). If you would like to test any of the examples in this section, you can use the var_dump() function. Note: The behavior of an automatic conversion to array is currently undefined.
Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being “f”, or should “f” become the first character of the string $a? The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes “f”, the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:
How can I get the only name of the current executing file?
Answer:
How can I embed a java programme in php file and what changes have to be done in php.ini file?
Answer:There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension. The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process. Example Code:
getProperty(’java.version’) . ‘
‘; echo ‘Java vendor=’ . $system->getProperty(’java.vendor’) . ‘
‘; echo ‘OS=’ . $system->getProperty(’os.name’) . ‘ ‘ . $system->getProperty(’os.version’) . ‘ on ‘ . $system->getProperty(’os.arch’) . ‘
‘; // java.util.Date example $formatter = new Java(’java.text.SimpleDateFormat’, “EEEE, MMMM dd, yyyy ‘at’ h:mm:ss a zzzz”); echo $formatter->format(new Java(’java.util.Date’)); ?>
The behaviour of these functions is affected by settings in php.ini. Table 1. Java configuration options Name java.class.path Default NULL Changeable PHP_INI_ALL
Name java.home java.library
Default NULL
Changeable PHP_INI_ALL PHP_INI_ALL
java.library.path NULL
JAVALIB PHP_INI_ALL
How can I find what type of images that the php version supports?
Answer: Using Imagetypes() function we can know Usage:
The table tbl_sites contains the following data. —————————————————-Userid sitename country —————————————————–1 sureshbabu indian 2 phpprogrammer andhra 3 php.net usa 4 phptalk.com germany 5 mysql.com usa 6 sureshbabu canada 7 phpbuddy.com pakistan 8. phptalk.com austria 9. phpfreaks.com sourthafrica 10. phpsupport.net russia 11. sureshbabu australia 12. sureshbabu nepal 13. phptalk.com italy
Write a select query that will displayed the duplicated site name and how many times it is duplicated?
Answer: SELECT sitename, COUNT(sitename) AS NumOccurrences FROM tbl_sites GROUP BY sitemail HAVING ( COUNT(sitemail) > 1 ) Or SELECT sitename