Thursday, December 31, 2009

Port Numbers

Services Port Numbers
HTTP 80
FTP 21
TELNET 23
POP3 110
SMTP 25
mIRC NoneN
NTP 123
PPTP 1723

If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?

Session depends on browser. If browser is closed then session is lost. The session
data will be deleted after session time out. If connection is lost and you recreate
connection, then session will continue in the browser.

What are the different functions in sorting an array?

Sorting functions in PHP:
asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()

How many ways we can pass the variable through the navigation between the pages?

At least 3 ways ways we can pass the variable through the navigation between the pages:
1. Put the variable into session in the first page, and get it back from session in the
next page.
2. Put the variable into cookie in the first page, and get it back from the cookie in
the next page.
3. Put the variable into a hidden form field, and get it back from the form in the
next page.

Tuesday, December 29, 2009

Sql injection

SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks.



Source:wikipedia.org

Tuesday, December 22, 2009

How do I find out the number of parameters passed into function?

func_num_args()
function returns the number of parameters passed in.

What's the difference between accessing a class method via -> and via ::?

:: is allowed to access methods that can perform static operations,
i.e. those, which do not require object initialization.

Are objects passed by value or by reference?

Everything is passed by value.

How do you call a constructor for a parent class?

parent::constructor($value)

What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of
all the variables than need to be saved, while __wakeup retrieves them.

Explain the differences echo, print and printf ?

echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string.
However, we can pass multiple parameters to echo, like:

and it will output the string "Welcome to PHP MySQL Guide!"

print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP.

printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.

What's the output of the ucwords function in this example?

$formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW
QUESTIONS");
print $formatted;

What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW
QUESTIONS.
ucwords() makes every first letter of every word capital, but it does not lower-case
anything else. To avoid this, and get a properly formatted string, it’s worth using
strtolower() first.

What’s the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand.
htmlentities translates all occurrences of character sequences that have different meaning in HTML.

What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The major difference is the length of the hash generated.
CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions

Monday, December 21, 2009

So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

Crypto usage in PHP is simple, but that doesn’t mean it’s free.

First off, depending on the data that you’re encrypting, you might have reasons to store a 32- bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

Write a simple program to get a row of information from a database?

$myrow = mysql_query("SELECT name,email FROM visitors ORDER by name LIMIT
1");
$data = mysql_fetch_row($myrow);
$name = $data[0];
$email = $data[1];
echo "A row from the database is name $name and email $email";

How do you remove the last letter from a string?

There are many ways to do this. An interviewer will be looking for you to use a compact method. Here is probably the simplest method:

$data = "One too many letterss";
$newdata = substr($data,0,-1);// now 'one too many letters'

What do you need to use the image functions in PHP?

I need to have access to the GD Library in order to use the image functions in PHP.

Sunday, December 20, 2009

What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?

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 document.

What changes I have to do in php.ini file for file uploading?

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

How can I set a cron and how can I execute it in Unix, Linux, and windows?

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
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 we get http://www.example.com/mailstock.php

What type of headers have to be added in the mail function to attach a file?

$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 Reply-to and Return-path in the headers of a mail function?

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.

How to store the uploaded file to the final location?

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.

jQuery's features break down accross eight major categories

# Core Functionality
Implement core jQuery functions as well as commonly used functions
# Selection and Traversal
Proving functions for finding content in documents and navigating among the content of the document

What is jQuery?

jQuery is great library for developing ajax based application. jQuery is great library for the JavaScript programmers, which simplifies the development of web 2.0 applications. You can use jQuery to develop cool web 2.0 applications. jQuery helps the programmers to keep code simple and concise. The jQuery library is designed to keep the things very simple and reusable.

jQuery library simplifies the process of traversal of HTML DOM tree. You can use jQuery to handle events, perform animation, and add the ajax support into your web applications with ease

#It is free, open JavaScript library
#Simplifies the task of creating highly responsive web page
#Work accross all modern browsers
#Abstract away browser-specific features, allowing you to concentrate on design
#Focusing on simplifying common scripting tasks
.Getting and manupulating page content
.Working with the modern browser event model
.Adding sophisticated effect

Wednesday, December 9, 2009

Public, Protected, and Private Properties

When defining a class member in the class definition, the developer
needs to specify one of these three access modifiers before declaring the member
itself. In case you are familiar with PHP 3 or 4’s object model, all class
members were defined with the var keyword, which is equivalent to public in
PHP 5. var has been kept for backward compatibility, but it is deprecated,
thus, you are encouraged to convert your scripts to the new keywords:
class MyClass {
public $publicMember = "Public member";
protected $protectedMember = "Protected member";
private $privateMember = "Private member";
function myMethod(){
// ...
}
}
$obj = new MyClass();


#Public members can be accessed both from outside an object by
using $obj->publicMember and by accessing it from inside the myMethod
method via the special $this variable (for example, $this->publicMember).
If another class inherits a public member, the same rules apply, and it
can be accessed both from outside the derived class’s objects and from
within its methods.
#Protected. Protected members can be accessed only from within an
object’s method—for example, $this->protectedMember. If another class
inherits a protected member, the same rules apply, and it can be accessed
from within the derived object’s methods via the special $this variable.
#Private. Private members are similar to protected members because they
can be accessed only from within an object’s method. However, they are
also inaccessible from a derived object’s methods. Because private properties
aren’t visible from inheriting classes, two related classes may
declare the same private properties. Each class will see its own private
copy, which are unrelated.

Constructors and Destructors

Constructors and Destructors are special methods that automatically called when every object is created or destroyed. So the idea is whenever object created stop constructing it and perform the constructor method and whenever we destroy an object, stop and do the destruction method.+

Constructors is more useful,its idle for any initializations,that a object may need before its actually going to be used


In PHP4 Constructors method have the same name as the class


class table{
function Table{
//a PHP4 constructor
}
}

In PHP5 its use as
class table{
function_construct{
//a PHP5 constructor


class Table{
public $legs;

function __construct(){
$this->legs=4;
}
}

$table= new Table();
echo $table->legs;
echo "
";
?>


another example:

class Table{
public $legs;
static public $total_tables=0;

function __construct($leg_count=4){
$this->legs=$leg_count;
Table::$total_tables++;
}
function __destruct(){
Table::$total_tables--;
}
}

$table= new Table();
echo $table->legs;
echo "
";

echo Table::$total_tables . "
"; //1
$t1=new Table(5);
echo Table::$total_tables . "
";
$t2=new Table(6);
echo Table::$total_tables . "
";
?>
Constructors and destructors do not have return types nor can they return values.
References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.
Constructors cannot be declared with the keyword virtual.
Constructors and destructors cannot be declared static, const, or volatile.
Unions cannot contain class objects that have constructors or destructors

Constructors and destructors obey the same access rules as member functions. For example, if you declare a constructor with protected access, only derived classes and friends can use it to create class objects.

source:lynda.com

Static modifier use in php

Static method doesn't require an instance (and may return one instead) and is more or less like a global function except for it is put in class' namespace (and therefore avoid collisions with other functions) and has access to class' private members.

So, use it whenever you're interested in these properties of the function.

class Student{
static $total_students=0;

static public function add_student(){
Student::$total_students++;
}

static function welcome_students($var="Hello"){
echo "{$var} students";
}
}

echo Student::$total_students;
echo "
";
echo Student::welcome_students();
echo "
";
echo Student::welcome_students("Welcome");
echo "
";
Student::$total_students=3;
echo Student::$total_students;
echo "
";
Student::$total_students=1;
echo Student::$total_students;
echo "
";

////Static variable shared through the inherited tree

class One{
static $foo;
}
class Two extends One{

}
class Three extends One{

}

One::$foo=1;
Two::$foo=2;
Three::$foo=3;
echo One::$foo;
echo "
";
echo Two::$foo;
echo "
";
echo Three::$foo;
?>

source:lynda.com and stackoverflow.com

Setters and Getters in Access Modifiers

The setter and getter method handlers agrees to read/write the values

class SetterGetterExample{
private $a=1;
public function get_a(){
//log_user_ip_address
return $this->a;
}
public function set_a($value){
$this->a=$value;
}
}

$example=new SetterGetterExample();

//echo $example->a;

echo $example->get_a();
$example->set_a(15);
echo "
";
echo $example->get_a();
?>

Dynamically set and get variable values. This is an abstract class that can be used to dynamically add variables to any class.

Access Modifiers

There are 3 access modifiers: Public; Private; and Protected

'Public' is the default modifier.

Public: Use In Everywhere
Private: Use in This class only
Protected: Use in This class and subclass


class Example{
public $a=1;
protected $b=2;
private $c=3;

function show_abc(){
echo $this->a;
echo $this->b;
echo $this->c;
}

public function hello_everyone(){
return "Hello Everyone"."
";
}
protected function hello_family(){
return "Hello Family"."
";
}
private function hello_me(){
return "Hello Me"."
";
}

function hello(){
$output = $this->hello_everyone();
$output .= $this->hello_family();
$output .= $this->hello_me();

return $output;
}

}

$example= new Example();
echo "public a:{$example->a}
";
//echo "protected b:{$example->b}
";
//echo "private c:{$example->c}
";
$example->show_abc();
echo "
";
echo "hello_everyone: {$example->hello_everyone()}
";
//echo "hello_me: {$example->hello_me()}
";
echo $example->hello();
?>

source:lynda.com

Understanding Class Inheritance

There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code. Class inheritance may sound complicated, but think of it this way. Consider a tree. A tree is made up of many parts, such as the roots that reside in the ground, the trunk, bark, branches, leaves, etc. Essentially inheritance is a connection between a child and its parent.

class Car{
var $wheels=4;
var $doors=4;

function wheelsdoors(){
return $this->wheels + $this->doors;
}
}

class CompactCar extends Car{
var $doors=2;
function wheelsdoors(){
return $this->wheels + $this->doors+ 100;
}
}

$car1 = new Car();
$car2 = new CompactCar();

echo $car1->wheels . "
";
echo $car1->doors . "
";
echo $car1->wheelsdoors() . "
";
echo "
";
echo $car2->wheels . "
";
echo $car2->doors . "
";
echo $car2->wheelsdoors() . "
";

echo "Car parents:".get_parent_class('Car')."
";
echo "CompactCar parents:".get_parent_class('CompactCar')."
";
echo "
";
echo is_subclass_of('Car','Car')? 'true' : 'false';
echo "
";
echo is_subclass_of('CompactCar','Car')? 'true' : 'false';
echo "
";
echo is_subclass_of('Car','CompactCar')? 'true' : 'false';


?>

Source: www.webreference.com

Would you initialize your strings with single quotes or double quotes?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless specifically need variable substitution.

What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of all the variables than need to be saved,
while __wakeup retrieves them.

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.

How can we encrypt the username and password using PHP?

1)
encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password");
2)
use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT into user (password, ...) VALUES (PASSWORD($password)), ...);

What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

Tuesday, December 8, 2009

Explain the differences between echo, print and printf?

Echo just outputs the contents following the construct to the screen.
print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string.
However, you can pass multiple parameters to echo, like:

echo 'Welcome ', 'to', ' ', 'php mysql guide!';

and it will output the string "Welcome to php mysql guide!"
print does not take multiple parameters.
It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP.
printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.

Saturday, December 5, 2009

Download usersonline script

Download usersonline script

Download phpaffiliate script

Download phpaffiliate script

Download Hitcounter script

Download Hit counter Script

Download Guest book script

Download Guest book script

Download greetings cards cript

Download greetings Card

Download downloadcounter script

Download downloadcounter Script

Download dating script

Download dating script

Download classifieds script

Download classifieds script

Download calendar script

Download calender script

Download bookmarks script

Download Bookmarks Script

Download adrotator script

Download Adrotator Script

Download Oscommerce script

Download Oscommerce Script

Explain the difference between FLOAT, DOUBLE and REAL

FLOATs store floating point numbers with 8 place accuracy and take up 4 bytes. DOUBLEs store floating point numbers with 16 place accuracy and take up 8 bytes. REAL is a synonym of FLOAT for now.

Explain the difference between BOOL, TINYINT and BIT.

Prior to MySQL 5.0.3: those are all synonyms. After MySQL 5.0.3: BIT data type can store 8 bytes of data and should be used for binary data.

What does myisamchk do?

It compressed the MyISAM tables, which reduces their disk usage.

Explain the difference between MyISAM Static and MyISAM Dynamic

MyISAM static all the fields have fixed width. The Dynamic MyISAM table would include fields such as TEXT, BLOB, etc. to accommodate the data types with various lengths. MyISAM Static would be easier to restore in case of corruption, since even though you might lose some data, you know exactly where to look for the beginning of the next record.

How can we know the number of days between two given dates using MySQL?

SELECT DATEDIFF('2007-03-07','2005-01-01');

How can I load data from a text file into a table?

We can use LOAD DATA INFILE file_name;
syntax to load data
from a text file. but we have to make sure that
a) data is delimited
b) columns and data matched correctly

What is the difference between char and varchar data types?

Set char to occupy n bytes and it will take n bytes even if u r
storing a value of n-m bytes
Set varchar to occupy n bytes and it will take only the required space
and will not use the n bytes
eg. name char(15) will waste 10 bytes if we store 'mysql', if each char
takes a byte
eg. name varchar(15) will just use 5 bytes if we store 'mysql', if each
char takes a byte. rest 9 bytes will be free.

What is the difference between GROUP BY and ORDER BY in Sql?

ORDER BY [col1],[col2],…,[coln];
Tells DBMS according to what columns
it should sort the result. If two rows will have the same value in col1
it will try to sort them according to col2 and so on.
GROUP BY
[col1],[col2],…,[coln]; Tells DBMS to group results with same value of
column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if
you want to count all items in group, sum all values or view average

What is the difference between Primary Key and Unique key?

Primary Key: A column in a table whose values uniquely identify the
rows in the table. A primary key value cannot be NULL.
Unique Key: Unique Keys are used to uniquely identify each row in the
table. There can be one and only one row for each unique key value. So
NULL can be a unique key.There can be only one primary key for a table but there can be more than one unique for a table.

How many ways we can we find the current date using MySQL?

SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()

How can we find the number of rows in a table using MySQL?

Use this for mysql
>SELECT COUNT(*) FROM table_name;

Explain Normalization concept?

The normalization process involves getting our data to conform to
three progressive normal forms, and a higher level of normalization
cannot be achieved until the previous levels have been achieved (there
are actually five normal forms, but the last two are mainly academic and
will not be discussed).The First Normal Form (or 1NF) involves removal of redundant data
from horizontal rows. We want to ensure that there is no duplication of
data in a given row, and that every column stores the least amount of
information possible (making the field atomic).Second Normal FormWhere the First Normal Form deals with redundancy of data across a
horizontal row, Second Normal Form (or 2NF) deals with redundancy of
data in vertical columns. As stated earlier, the normal forms are
progressive, so to achieve Second Normal Form, your tables must already
be in First Normal Form.Third Normal Form
I have a confession to make; I do not often use Third Normal Form. In
Third Normal Form we are looking for data in our tables that is not
fully dependant on the primary key, but dependant on another value in
the table

Give the syntax of Grant and Revoke commands?

The generic syntax for grant is as following
> GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY
[password]
now rights can be
a) All privileges
b) combination of create, drop, select, insert, update and delete etc.We can grant rights on all databse by using *.* or some specific
database by database.* or a specific table by database.table_name
username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition
password is simply the password of userThe generic syntax for revoke is as following
> REVOKE [rights] on [database/s] FROM [username@hostname]
now rights can be as explained above
a) All privileges
b) combination of create, drop, select, insert, update and delete etc.
username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition

What is maximum size of a database in MySQL?

If the operating system or filesystem places a limit on the number
of files in a directory, MySQL is bound by that constraint.The efficiency of the operating system in handling large numbers of
files in a directory can place a practical limit on the number of tables
in a database. If the time required to open a file in the directory
increases significantly as the number of files increases, database
performance can be adversely affected.
The amount of available disk space limits the number of tables.
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM
storage engine in MySQL 3.23, the maximum table size was increased to
65536 terabytes (2567 – 1 bytes). With this larger allowed table size,
the maximum effective table size for MySQL databases is usually
determined by operating system constraints on file sizes, not by MySQL
internal limits.The InnoDB storage engine maintains InnoDB tables within a tablespace
that can be created from several files. This allows a table to exceed
the maximum individual file size. The tablespace can include raw disk
partitions, which allows extremely large tables. The maximum tablespace
size is 64TB.
The following table lists some examples of operating system file-size
limits. This is only a rough guide and is not intended to be definitive.
For the most up-to-date information, be sure to check the documentation
specific to your operating system.
Operating System File-size LimitLinux 2.2-Intel 32-bit 2GB (LFS: 4GB)
Linux 2.4+ (using ext3 filesystem) 4TB
Solaris 9/10 16TB
NetWare w/NSS filesystem 8TB
Win32 w/ FAT/FAT32 2GB/4GB
Win32 w/ NTFS 2TB (possibly larger)
MacOS X w/ HFS+ 2TB

Friday, December 4, 2009

What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?

In MySql, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names
that begin with the table name and have an extension to indicate the
file type.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension,

How many tables will create when we create table, what are they?

The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension,

How many values can the SET function of MySQL take?

MySQL set can take zero or more values but at the maximum it can
take 64 values

What is the maximum length of a table name, database name, and fieldname in MySQL?

The following table describes the maximum length for each type of
identifier.
Identifier Maximum Length
(bytes)
Database 64
Table 64
Column 64
Index 64
Alias 255
There are some restrictions on the characters that may appear in
identifiers:

What are the advantages of stored procedures, triggers, indexes?

A stored procedure is a set of SQL commands that can be compiled and
stored in the server. Once this has been done, clients don’t need to
keep re-issuing the entire query but can refer to the stored procedure.
This provides better overall performance because the query has to be
parsed only once, and less information needs to be sent between the
server and the client. You can also raise the conceptual level by having
libraries of functions in the server. However, stored procedures of
course do increase the load on the database server system, as more of
the work is done on the server side and less on the client (application)
side.Triggers will also be implemented. A trigger is effectively a type of
stored procedure, one that is invoked when a particular event occurs.
For example, you can install a stored procedure that is triggered each
time a record is deleted from a transaction table and that stored
procedure automatically deletes the corresponding customer from a
customer table when all his transactions are deleted.Indexes are used to find rows with specific column values quickly.
Without an index, MySQL must begin with the first row and then read
through the entire table to find the relevant rows. The larger the
table, the more this costs. If the table has an index for the columns in
question, MySQL can quickly determine the position to seek to in the
middle of the data file without having to look at all the data. If a
table has 1,000 rows, this is at least 100 times faster than reading
sequentially. If you need to access most of the rows, it is faster to
read sequentially, because this minimizes disk seeks.

How can we repair a MySQL table?

The syntex for repairing a MySQL table is
REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
This command will repair the table specified if the quick is given the
MySQL will do a repair of only the index tree if the extended is given
it will create index row by row

How can I retrieve values from one database server and store them in other database server using PHP?

We can always fetch from one database and rewrite to another. here
is a nice solution of it.$db1 = mysql_connect("hostname","username","password")
mysql_select_db(”db1″, $db1);

$res1 = mysql_query("query",$db1);
$db2 = mysql_connect("hostname","username","password");

mysql_select_db("db2″, $db2);
$res2 = mysql_query("query",$db2);
At this point you can only fetch records from you previous ResultSet,
i.e $res1 – But you cannot execute new query in $db1, even if you
supply the link as because the link was overwritten by the new db, So at this point the following script will fail

$res3 = mysql_query("query",$db1); //this will failSo how to solve that?
take a look below.

$db1 = mysql_connect("hostname","username","password");
mysql_select_db("db1″, $db1);
$res1 = mysql_query("query",$db1);
$db2 = mysql_connect("hostname","username","password", true)
mysql_select_db("db2", $db2);
$res2 = mysql_query("query",$db2);
So mysql_connect has another optional boolean parameter which
indicates whether a link will be created or not. as we connect to the
$db2 with this optional parameter set to ‘true’, so both link will
remain live.
now the following query will execute successfully.
$res3 = mysql_query("query",$db1);

How can we optimize or increase the speed of a MySQL select query?

# First of all instead of using select * from table1, use select
column1, column2, column3.. from table1
# Look for the opportunity to introduce index in the table you are
querying.
# Use limit keyword if you are looking for any specific number of
rows from the result set.

How can we take a backup of a MySQL table and how can we restore it. ?

To backup: BACKUP TABLE tbl_name[,tbl_name…] TO
‘/path/to/backup/directory’
RESTORE TABLE tbl_name[,tbl_name…] FROM ‘/path/to/backup/directory’mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or
for transferring the data to another SQL server (not necessarily a MySQL
server). The dump will contain SQL statements to create the table and/or
populate the table.
-t, –no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, –no-data
Don’t write any row information for the table. This is very useful if
you just want to get a dump of the structure for a table!

How can we encrypt and decrypt a data present in a MySQL table using MySQL?

AES_ENCRYPT () and AES_DECRYPT ()

Explain advantages of MyISAM over InnoDB?

Advantages of MyISAM over InnoDB

Much more conservative approach to disk space management - each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.

Explain advantages of InnoDB over MyISAM?

Advantages of InnoDB over MyISAM

Row-level locking, transactions, foreign key constraints and crash recovery.

Wednesday, December 2, 2009

What is the possible advantages/disadvantages of page caching? How can you prevent caching of a certain page?

When we 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 document

How can I set a cron and how can I execute it in Unix, Linux, and windows?

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

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

Tuesday, December 1, 2009

What type of headers have to be added in the mail function to attach a file?

$boundary = '--' . md5( uniqid ( rand() ) );
$headers = "From: \"Me\"\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";

How to store the uploaded file to the final location?

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 include and require?

It's how they handle failures.
If the file is not found by require(), it will cause a fatal error and halt the execution of the script.
If the file is not found by include(), a warning will be issued, but execution will continue.

How To Read the Entire File into a Single String?

If you have a file, and you want to read the entire file into a single string, you can use the
file_get_contents() function. It opens the specified file, reads all characters in the file, and
returns them in a single string. Here is a PHP script example on how to
file_get_contents():

$file = file_get_contents("/windows/system32/drivers/etc/services");
print("Size of the file: ".strlen($file)."\n");
?>

This script will print:
Size of the file: 2111

How can we send mail using JavaScript?

No, we can't send mail using Javascript. But we can execute a client side email client to send the email using mailto: code
Using clientside email client
function mailfunction(form)
{
tdata=document.myform.tbox1.value;
location="mailto:mailid@domain.com?subject="+tdata+"/MYFORM";
return true; }

What is the functionality of STRSTR() and STRISTR()

STRSTR find first occurance of a string.

string strstr ( string haystack, string needle )

string strstr ( string haystack, string needle ) returns part of haystack string from the first
occurrence of needle to the end of haystack

$email = 'programmerinphp@gmail.com';
$domain = strstr($email, '@');
echo $domain; // prints @gmail.com
?>

This function is case-sensitive

STRISTR is same as STRSTR but it is case insensitive

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off