What is switch statement in php ?
Switch is a conditional statement , which perform specific action according to various condition. It is equivalent to If else strcutures. Syntax :
[php]switch (variable) {
case label1:
This block will execute if variable=label1;
break;
case label2:
This block will execute if variable=label2;
break;
case label3:
This block will execute if variable=label3;
break;
default:
This block will execute if variable not matching with any label;
}
[/php]
variable can be integer,string, character, float, double etc..
switch is similar to if..elseif..esle statement.
Note : break is required , if you missed break then it will check next case and execute default case also.
<?php
$num = 2;
switch($num){
case 1:
echo "My number is One";
break;
case 2:
echo "My number is Two";
break;
case 3:
echo "My number is Three";
break;
default :
echo "Not matching";
}
?>
Output : My number is Two
1. Checking vowel & consonant(Only for Small case letter)
<?php
$c = 'u';
switch($c){
case 'a':
echo "$c is Vowel";
break;
case 'e':
echo "$c is Vowel";
break;
case 'i':
echo "$c is Vowel";
break;
case 'o':
echo "$c is Vowel";
break;
case 'u':
echo "$c is Vowel"; break;
default:
echo "$c is Consonant ";
}
?>
Output : u is Vowel
2. Wishing birthday on current date
<?php $dob = date("d/m");
switch($dob){ case "10/02":
echo "Happy birthday Somnath";
break;
case "23/07":
echo "Happy birthday Santosh";
break;
case "18/08":
echo "Happy birthday Anil";
break;
case "04/09":
echo "Happy birthday Jassi";
break;
case "11/12":
echo "Happy birthday Ritesh";
break;
default: echo "No birthday party";
} ?>
if Today's date is – 23/07/2011
Output : Happy birthday Santosh
Normalization Resolved Normalization is one of the favorite topics of interviewee. It does not matter whether you have mentioned DBMS in your resume or not .This question is going to come and the funny part is that all of us know
what is normalization?
What are the different types of normalization?
So when this question on being asked the interviewer who have already prepared for it start with the history of normalization and end with the geography of normalization but when the next question for which they have not prepared i.e. apply normalization in real case scenario.
Now here comes the real part of normalization and just because of not proper concepts, people end up confusing themselves. So the idea is to not only to get familiar with normalization but also how to apply it in real time scenario.
What is Normalization?
Database designed based on ER model may have some amount of inconsistency, ambiguity and redundancy. To resolve these issues some amount of refinement is required. This refinement process is called as Normalization. I know all of you are clear with the definition, let’s go with :
what is the need of normalization?
What are the problems we can face if we proceed without normalization?
What are the advantages of normalization?
Asking question to oneself is the best way to get familiar with all the concepts.
The need of Normalization
I am going to show you one simple E-R model database.
Student Details
Course Details
Result details
1001 Ram 11/09/1986
M4 Basic Maths 7
11/11/2004 89 A
1002 Shyam 12/08/1987
M4 Basic Maths 7
11/11/2004 78 B
1001 Ram 23/06/1987
H6 4
11/11/2004 87 A
1003 Sita 16/07/1985
C3 Basic Chemistry 11
11/11/2004 90 A
1004 Gita 24/09/1988
B3 8
11/11/2004 78 B
1002 Shyam 23/06/1988
P3 Basic Physics 13
11/11/2004 67 C
1005 Sunita 14/09/1987
P3 Basic Physics 13
11/11/2004 78 B
1003 Sita 23/10/1987
B4 5
11/11/2004 67 C
1005 Sunita 13/03/1990
H6 4
11/11/2004 56 D
1004 Gita 21/08/1987
M4 Basic Maths 7
11/11/2004 78 B
In first look the above table is looking so arranged and well in format but if we try to find out what exactly this table is saying to us , we can easily figure out the various anomalies in this table . Ok let me help you guys in finding out the same.
Insert Anomaly: We cannot insert prospective course which does not have any registered student or we cannot insert student details that is yet to register for any course.
Update Anomaly: if we want to update the course M4’s name we need to do this operation three times. Similarly we may have to update student 1003’s name twice if it changes.
Delete Anomaly: if we want to delete a course M4 , in addition to M4 occurs details , other critical details of student also will be deleted. This kind of deletion is harmful to business. Moreover, M4 appears thrice in above table and needs to be deleted thrice.
Duplicate Data: Course M4’s data is stored thrice and student 1002’s data stored twice .This redundancy will increase as the number of course offerings increases.
Process of normalization:
Before getting to know the normalization techniques in detail, let us define a few building blocks which are used to define normal form.
Determinant : Attribute X can be defined as determinant if it uniquely defines the value Y in a given relationship or entity .To qualify as determinant attribute need NOT be a key attribute .Usually dependency of attribute is represented as X->Y ,which means attribute X decides attribute Y.
Example: In RESULT relation, Marks attribute may decide the grade attribute .This is represented as Marks->grade and read as Marks decides Grade.
Marks -> Grade
In the result relation, Marks attribute is not a key attribute .Hence it can be concluded that key attributes are determinants but not all the determinants are key attributes.
Functional Dependency: Yes functional dependency has definition but let’s not care about that. Let’s try to understand the concept by example. Consider the following relation :
IName- Name of the instructor who delivered the course
Room#-Room number which is assigned to respective instructor
Marks- Scored in Course Course# by student Student #
Grade –Obtained by student Student# in course Course #
Student#,Course# together (called composite attribute) defines EXACTLY ONE value of marks .This can be symbolically represented as
Student#Course# Marks
This type of dependency is called functional dependency. In above example Marks is functionally dependent on Student#Course#.
Other Functional dependencies in above examples are:
Course# -> CourseName
Course#-> IName(Assuming one course is taught by one and only one instructor )
IName -> Room# (Assuming each instructor has his /her own and non shared room)
Marks ->Grade
Formally we can define functional dependency as: In a given relation R, X and Y are attributes. Attribute Y is functional dependent on attribute X if each value of X determines exactly one value of Y. This is represented as :
X->Y
However X may be composite in nature.
Full functional dependency: In above example Marks is fully functional dependent on student#Course# and not on the sub set of Student#Course# .This means marks cannot be determined either by student # or Course# alone .It can be determined by using Student# and Course# together. Hence Marks is fully functional dependent on student#course#.
CourseName is not fully functionally dependent on student#course# because one of the subset course# determines the course name and Student# does not having role in deciding Course name .Hence CourseName is not fully functional dependent on student #Course#.
Student#
Marks
Course#
Formal Definition of full functional dependency : In a given relation R ,X and Y are attributes. Y is fully functionally dependent on attribute X only if it is not functionally dependent on sub-set of X.However X may be composite in nature.
Partial Dependency: In the above relationship CourseName,IName,Room# are partially dependent on composite attribute Student#Course# because Course# alone can defines the coursename, IName,Room#.
Room#
IName
CourseName
Course#
Student#
Formal Definition of Partial dependency: In a given relation R, X and Y are attributes .Attribute Y is partially dependent on the attribute X only if it is dependent on subset attribute X .However X may be composite in nature.
Transitive Dependency: In above example , Room# depends on IName and in turn depends on Course# .Here Room# transitively depends on Course#.
IName
Room#
Course#
Similarly Grade depends on Marks,in turn Marks depends on Student#Course# hence Grade
Fully transitively depends on Student#Course#.
Key attributes : In a given relationship R ,if the attribute X uniquely defines all other attributes ,then the attribute X is a key attribute which is nothing but the candidate key.
Ex: Student#Course# together is a composite key attribute which determines all attributes in relationship REPORT(student#,Course#,CourseName,IName,Room#,Marks,Grade)uniquely.Hence Student# and Course# are key attributes.
Types of Normal Forms
First Normal Form(1NF)
A relation R is said to be in first normal form (1NF) if and only if all the attributes of the relation R are atomic in nature
Student Details
Course Details
Result details
1001 Ram 11/09/1986
M4 Basic Maths 7
11/11/2004 89 A
1002 Shyam 12/08/1987
M4 Basic Maths 7
11/11/2004 78 B
1001 Ram 23/06/1987
H6 4
11/11/2004 87 A
1003 Sita 16/07/1985
C3 Basic Chemistry 11
11/11/2004 90 A
1004 Gita 24/09/1988
B3 8
11/11/2004 78 B
1002 Shyam 23/06/1988
P3 Basic Physics 13
11/11/2004 67 C
1005 Sunita 14/09/1987
P3 Basic Physics 13
11/11/2004 78 B
1003 Sita 23/10/1987
B4 5
11/11/2004 67 C
1005 Sunita 13/03/1990
H6 4
11/11/2004 56 D
1004 Gita 21/08/1987
M4 Basic Maths 7
11/11/2004 78 B
Table shown above Student Details ,Course Details and Result Details can be further divided. Student Details attribute is divided into Student#(Student Number) , Student Name and date of birth. Course Details is divided into Course# ,Course Name,Prerequisites and duration. Similarly Results attribute is divided into DateOfexam,Marks and Grade.
Second Normal Form (2NF)
A relation is said to be in Second Normal Form if and only If :
It is in the first normal form ,and
No partial dependency exists between non-key attributes and key attributes.
Let us re-visit 1NF table structure.
Student# is key attribute for Student ,
Course# is key attribute for Course
Student#Course# together form the composite key attributes for result relationship.
Other attributes are non-key attributes.
To make this table 2NF compliant, we have to remove all the partial dependencies.
StudentName and DateOfBirth depends only on student#.
CourseName,PreRequisite and DurationInDays depends only on Course#
DateOfExam depends only on Course#.
To remove this partial dependency we need to split Student_Course_Result table into four separate tables ,STUDENT ,COURSE,RESULT and EXAM_DATE tables as shown in figure.
STUDENT TABLE
Student #
Student Name
DateofBirth
1001
Ram
Some value
1002
Shyam
Some value
1003
Sita
Some value
1004
Geeta
Some value
1005
Sunita
Some value
COURSE TABLE
Course#
CourseName
Duration of days
C3
Bio Chemistry
3
B3
Botany
8
P3
Nuclear Physics
1
M4
Applied Mathematics
4
H6
American History
5
B4
Zoology
9
RESULT TABLE
Student#
Course#
Marks
Grade
1001
M4
89
A
1002
M4
78
B
1001
H6
87
A
1003
C3
90
A
1004
B3
78
B
1002
P3
67
C
1005
P3
78
B
1003
B4
67
C
1005
H6
56
D
1004
M4
78
B
EXAM DATE Table
Course#
DateOfExam
M4
Some value
H6
Some value
C3
Some value
B3
Some value
P3
Some value
B4
Some value
In the first table (STUDENT) ,the key attribute is Student# and all other non-key attributes, StudentName and DateOfBirth are fully functionally dependant on the key attribute.
In the Second Table (COURSE) , Course# is the key attribute and all the non-key attributes, CourseName, DurationInDays are fully functional dependant on the key attribute.
In third table (RESULT) Student#Course# together are key attributes and all other non key attributes, Marks and Grade are fully functional dependant on the key attributes.
In the fourth Table (EXAM DATE) Course# is the key attribute and the non key attribute ,DateOfExam is fully functionally dependant on the key attribute.
At first look it appears like all our anomalies are taken away ! Now we are storing Student 1003 and M4 record only once. We can insert prospective students and courses at our will. We will update only once if we need to change any data in STUDENT,COURSE tables. We can get rid of any course or student details by deleting just one row.
Let us analyze the RESULT Table
Student#
Course#
Marks
Grade
1001
M4
89
A
1002
M4
78
B
1001
H6
87
A
1003
C3
90
A
1004
B3
78
B
1002
P3
67
C
1005
P3
78
B
1003
B4
67
C
1005
H6
56
D
1004
M4
78
B
We already concluded that :
All attributes are atomic in nature
No partial dependency exists between the key attributes and non-key attributes
RESULT table is in 2NF
Assume, at present, as per the university evaluation policy,
Students who score more than or equal to 80 marks are awarded with “A” grade
Students who score more than or equal to 70 marks up till 79 are awarded with “B” grade
Students who score more than or equal to 60 marks up till 69 are awarded with “C” grade
Students who score more than or equal to 50 marks up till 59 are awarded with “D” grade
The University management which is committed to improve the quality of education ,wants to change the existing grading system to a new grading system .In the present RESULT table structure ,
We don’t have an option to introduce new grades like A+ ,B- and E
We need to do multiple updates on the existing record to bring them to new grading definition
We will not be able to take away “D” grade if we want to.
2NF does not take care of all the anomalies and inconsistencies.
Third Normal Form (3NF)
A relation R is said to be in 3NF if and only if
It is in 2NF
No transitive dependency exists between non-key attributes and key attributes.
In the above RESULT table Student# and Course# are the key attributes. All other attributes, except grade are non-partially , non – transitively dependant on key attributes. The grade attribute is dependant on “Marks “ and in turn “Marks” is dependent on Student#Course#. To bring the table in 3NF we need to take off this transitive dependency.
Student#
Course#
Marks
1001
M4
89
1002
M4
78
1001
H6
87
1003
C3
90
1004
B3
78
1002
P3
67
1005
P3
78
1003
B4
67
1005
H6
56
1004
M4
78
UpperBound
LowerBound
Grade
100
95
A+
94
90
A
89
85
B+
84
80
B
79
75
B-
74
70
C
69
65
C-
After Normalizing tables to 3NF , we got rid of all the anomalies and inconsistencies. Now we can add new grade systems, update the existing one and delete the unwanted ones.
Hence the Third Normal form is the most optimal normal form and 99% of the databases which require efficiency in
This step by step procedure is for those users who use Windows and facing slowdown of their computer systems which may cause due to several reasons. Just follow those listed points; you don’t need to use any 3rd party tool to cleanup files and to respond your system in faster way.
I presume that you have basic knowledge of running commands through run commands and know to browse files and folders if stated to do so. I also presume that your system is not infected with any spywares, malwares or viruses. (Then these steps would go in vain)
Go to run commandand type regedit to open registry editor. (shortcut key:windows key + R)
Now browse through the below given path
HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Explorer/VolumeCaches
i.e. at first click on HKEY_LOCAL_MACHINE then software under its tree structure then windows and so on…..
Reach upto VolumeCaches, and then delete every folder listed under it one by one. (click on folder and press del key then click on yes)
Open run command again and type%temp% to list contents of temporary files under the present user account.
The path to that specific folder is “C:\Users\username\AppData\Local\Temp” (change username to original value like Aliencoders or Jassi etc.)
Open run command once more and type temp then press enter to list the contents under Windows Temporary Files ie. “C:\Windows\Temp”
Remove Temporary internet files associates with Internet Explorer. (I am sure most of the users are still using this system’s default browser ) which is at C:/Users/username/AppData/Local/Microsoft/Windows/Temporary Internet Files
Note: You can delete it through Internet Explorer browser also.
open internet explorer
click on tools (check at right side top)
then click on Internet Option (usually it will be at last in the list )
click on general tab if you are not at general tab.(by default it will be in general tab only)
click on delete under Browsing history (which will be after Home page) or click on settings under the same heading and click on view files button. You will be taken to the same folder about which I was talking.
Delete apps which are not required or frequently used from install/uninstall wizard.
You can browse that wizard by typing appwiz.cplat run prompt. (Now you know to open run command prompt and to type something? If, not then do it again because you will need it frequently)
Open Run command and type msconfig to open System Configuration settings
then go through each tab minutely and if you feel you don’t need any application under boot services, startup etc just uncheck those applications and press apply and then Ok. (settings will be effective after restart which you can do later too!)
Open Run command one more time. Type cleanmgr and press enter to cleanup unwanted files (unwanted/unused according to system software )
Click on My Files only and then choose drive to do system cleanup.
Remove/move (cut and paste) materials from desktop, My Documents, My music, My pictures , Downloads (C:\Users\Jaiswal\Downloads) folders (it will be usually in C drive where O.S. is installed)
Note:Don’t keep huge file size stuffs , important stuffs on desktop or in my documents or even in C directory. ( If your system crashes or you need to install fresh Windows O.S. then these files will get deleted. So better to save in other directory like D:\ or E:\ etc)
If you wish to clean unwanted stuffs through GUI based applicationand don’t want to go through the above mentioned steps then go for Ccleaner
How to transfer the domain from one hosting provider or registrar to other
It’s always important to host your website to a reliable web hosting service provider. But sometimes due to lack of knowledge or much experience on these things we register our domain and signup for the hosting plans. Although all renowned hosting providers are doing great job but I preferably choose either blueshost.com or godaddy.com
I had few issues with godaddy.com, that’s why I postponed the plan to host my domain there and finally chose bluehost.com as I was using it from last 2 years without any hassle and Customer Support Service is awesome. I liked online chatting also 😉
These simple steps to transfer your domain from one hosting service provider to another or from one registrar to another will work for any such situation for any service provider. (Few things may change though)
Let’s start step by step to transfer domain from one registrar or one hosting provider to another Step 1
Make sure you have access to your present account and the domain name that you wish to transfer is unlocked. If not then either go to your admin panel (cpanel usually) and under domain section you will see domain manager icon/link. Click on that and then you will see unlock domain option.
If you are not able to figure out how to unlock the domain name and how to see/change EPP(Auth) code which you would be the basic step to transfer your domain name successfully. Contact the current registrar or the hosting provider to unlock the domain and to provide EPP or authorization code.
Step 2
I assume you are done with Step 1 and your domain is unlocked and you have EPP code with you. Now make sure your whois database information is upto date and turn off the privacy domain if it’s turn on else leave it.
This step is required because your new registrar will send the mail to the email id that appears in whois database for that domain name.
Step 3
Now either you will register the domain and host too with the same client or registrar may be different from the hosting provider. But I would suggest try to host your domain from whom you registered. For example: Blue Host Inc is a hosting provider and you can register the domain name from this company too. Its registrar is FastDomain Inc. So, choose hosting provider carefully and do the needful.
This step is required to make transferring easier. Once you register and have account with a new hosting provider and your account is verified there. If you are new to that hosting provider it may take 48 hours to get verified or it may take just few hours (for me it took 6 hours approx.)
Step 4
It is highly recommended that pointing the name servers to your new hosting provider before initiating a registration transfer because transfers can take 3-10 days to complete. During this time the name servers cannot be modified. If you point the name servers to it before starting a transfer, your domain will be pointed to it (bulehost DNS in my case) during the duration of the transfer and your site will show what is on Bluehost's servers.
Go to old account (I mean the existing account i.e. old one) and point the name server to point to your newly registered web hosting DNS. In my case it was bluehost, so
I updated Bluehost nameservers as:
ns1.bluehost.com (Primary Server Hostname)
ns2.bluehost.com (Secondary Server Hostname)
Once you have made this change, allow 24-48 hours for the changes to update across DNS resolvers worldwide, and your domain will be pointed to Bluehost’s name servers.
Step 5
Now you can login to your newly registered account’s dashboard. (For me it was bluehost cPanel) and click on the domain manager under the domain section.
Then Select the domain that you wish to transfer. (One can have as many domains linked with one account as possible). Then you will fugure out that there will be a link/icon to “Tranfer this domain to your account” (for me it showed aliencoders.org)
Read the information carefully and provide the EPP code that you got from your older account and click on continue.
Step 6
Now you will get email on the same email id that you have updated in your old account which will contain the verification code without which you will not be able to proceed.
So, if you don’t have access to the provided email address, contact the current registrar to update the WHOIS contact information. It will take hardly few minutes if everything is fine). I got within 10 minutes.
Step 7
I assume you got the confirmation code that I stated at step 6 and now use that code as the second verification code required by new registrar and click on continue button.
And update nameservers if required, and other option like renewal scheme, contact information, privacy option. Then agree to all terms and click on Add transfer/start transfer process.
Now your old registrar will contact you and will mail you to confirm the transfer. It would take 2-3 days to get mail from old registrar, so be patient. Then respond accordingly.
Note: These are a few points to keep in mind while transferring the domain name registration.
The transfer process takes 3-10 days once initiated. Ensure the domain name will not expire in this time frame to avoid potential problems with the transfer. If recently renewed, make sure it is at least 30 days after the renewal date to ensure you do not lose the additional time added with the current registrar.
When transferring a domain to bluehost, ICANN requires an additional year is added to the domain's current expiration date. The cost for this is $11.95 per domain. If your account has an available "Free Domain" credit, it will automatically be applied during the checkout process.
ICANN policy does not allow a domain name to be transferred from a registrar within 60 days of the date or registration or renewal.
If you would like to start hosting the domain with bluehost within 24-48 hours rather than waiting to complete registry transfer, contact the current registrar before starting the transfer and modify the DNS to ns1.bluehost.com and ns2.bluehost.com. Once the transfer is initiated, no change to the DNS can be made until the transfer is either canceled or has completed. (I did so and it worked perfectly for me)
Source: Blue Host Inc (Last four points mainly) and this article is based on bluehost process because I transferred here only.
Image source:http://domainnames.nikenya.com
Visitor Rating: 5 Stars
Visitor Rating: 3 Stars