+ All Categories
Home > Documents > CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts...

CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts...

Date post: 01-Apr-2015
Category:
Upload: efren-towle
View: 213 times
Download: 0 times
Share this document with a friend
Popular Tags:
84
CREATED BY : VIRAL M.KORADIYA
Transcript
Page 1: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

CREATED BY : VIRAL M.KORADIYA

Page 2: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<a> </a>

Anchor elements are defined by the <a> element. The <a> element accepts several attributes, but either the Name or HREF attribute is required.

Page 3: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Attribute HREFNAMETARGET

Page 4: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The href Attribute

if the HREF (Hypertext Reference) attribute is present, the text between the opening and closing anchor elements becomes a hypertext link.

Example:<a href =“abc.html”> link </a>

Page 5: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The target Attribute

The target attribute defines where the linked document will be opened.

Example:

<a href="http://www.google.com/"target="_blank">Visit Google!</a>

Page 6: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The name AttributeWhen the name attribute is used, the <a> element defines a named anchor inside a HTML document.

Named anchor are not displayed in any special way. They are invisible to the reader.

Named anchor syntax:<a name="label">Any content</a> The link syntax to a named anchor:  <a href="#label">Any content</a>

Page 7: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Example:

A named anchor inside an HTML document:<a name="tips">Useful Tips Section</a>

A link to the Useful Tips Section from the same document: 

<a href="#tips">Jump to the Useful Tips Section</a>

Page 8: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Line Breaks<BR><HR>

<BR> The line break element specifies that a new

line must be started at the given point.

Page 9: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<HR> A horizontal rule(<HR>) element is a divider

between sections of text, such as a full-width horizontal rule or a similar graphic.

Attribute:<hr align=left><hr align=right><hr align=center><hr color=name><hr size=value><hr width=number\percent><hr noshade>

Page 10: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.
Page 11: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<HTML><HEAD> <TITLE></TITLE></HEAD><BODY></BODY></HTML>

Page 12: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Document Tag<HTML> </HTML><HEAD> </HEAD><BODY> </BODY><TITLE> </TITLE><!-- --> comment

Page 13: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Body TagAttribute

bgcolor Example <body bgcolor=red>

Text Example <body text=blue>

Page 14: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Comment<html> <head> <title> Example of comment</title> </head> <body> hello <!– this is comment -- > </body> </html>

Page 15: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Text Formatting Tag<H1> </H1> to <H6> </H6><P> </P><Pre> </Pre><B> </B><U> </U><I> </I><Tt> </Tt><Strike> </Strike><Sub> </Sub>

Page 16: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Sup> </Sup><Big> </Big><Base><Strong> </Strong><Small> </Small><Font> </Font><Basefont> <Basefont><Blink><Marquee>

Page 17: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<H1> </H1> to <H6> </H6>HTML defines six levels of heading<H1> </H1><H2> </H2><H3> </H3><H4> </H4><H5> </H5><H6> </H6>

Page 18: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<P> </P>

The paragraph element indicates a paragraph of text.

To align paragraph use ALIGN =left/right/center attribute and values have been added to the <p> element.

<p align=left><p align=right><p align=center>

Page 19: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Pre> </Pre>The preformatted text element presents blocks

of text in fixed-width font and is suitable for text that has been formatted on-screen or in a mono-spaced font.

Page 20: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<B> </B>This tag is specified text should be bold

<U> </U>• This tag is specified text should be

underline.

Page 21: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<i> </i>This tag is specified text should be Italic

style.

<TT> </TT>

• The TeleType element specified that the text be rendered in fixed-width typewriter font where available.

Page 22: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Strike> </Strike>The <strike> </strike> element states that the

enclosed text should be displayed with a horizontal line striking through the text.

Page 23: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Sub> </Sub>The <Sub> element specifies that the

enclosed text should be displayed as a subscript.

<Sup> </Sup>

• The <Sup> element specifies that the enclosed text should be displayed as a superscript.

Page 24: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Big> </Big>The <Big> element specifies that the

enclosed text should be displayed, if practical, using a big font compared with the current font.

Page 25: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Strong> </Strong>The strong element can be used to indicate

strong typographic.

<Small> </Small>

• The <Small> element specifies that the enclosed text should be displayed, if practical, using a small font compared with current font.

Page 26: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Base>The <base> tag specifies a default address or a

default target for all links on a page.The <base> tag goes inside the head element.Attribute :-HREF Example:<head><base href="D:\\"><body>

Page 27: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Microsoft internet explorer support different-sized fonts within HTML documents.The element is <font size=value>. Valid values range from 1 to 7. the default font size is 3.

Page 28: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Font attributesSize : 1 to 7Color : color name & #rrggbb The color attribute sets the color that text

appears on screen. #rrggbb is a hexadecimal color denoting an RGB color values.

Face : name The face attribute sets the typeface used to

display the text on-screen. The typeface displayed already must be installed on the user’s computer.

Page 29: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Example<font size =5> hello </font> or <font color=red> hello </font> or <font color=#ff0000> hello </font><font face=“Courier New”> hello </font>

Page 30: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<basefont>The <basefont> tag specifies a default font-

color, font-size, or font-family for all the text in a document.

Example: <head> <basefont color="red" size="5"> </head>

Page 31: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Blink>

Surrounding any text with this element causes the selected text to blink on the viewing page. This can add extra emphasis to selected text.

Example<blink> this text blink on the page </blink>

Note: the <blink>…</blink> element currently is supported only by Netscape browser.

Page 32: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<Marquee> </Marquee>

The <marquee> element allows you to create a region of text that can be made to scroll across the screen.

Example:<marquee> Hello student </marquee>

Page 33: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

AttributesAlign

This attribute can be set to TOP,MIDDLE and BOTTOM specifies that the text around the marquee should align with the top, middle and bottom of the marquee.

Example: <marquee align=top> hello </marquee>

Page 34: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Behavior

This can be set to SCROLL, SLIDE and ALTERNATE. It specifies how the text displayed in the marquee should behave.

Example:<marquee behavior=alternate>hello</marquee><marquee behavior=scroll>hello</marquee><marquee behavior=slide>hello</marquee>

Page 35: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Direction This specifies in which direction the

<marquee> text should scroll. The default is LEFT. Which means that the text will scroll to the left from the right-hand side of the marquee. This attribute also set to RIGHT, which causes the marquee text to scroll from the left to the right.

Example: <marquee direction=right>hello</marquee>

Page 36: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

FramesWith frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others.

The disadvantages of using frames are:

The web developer must keep track of more HTML documents It is difficult to print the entire page

Page 37: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The Frameset Tag

The <frameset> tag defines how to divide the window into frames

Each frameset defines a set of rows or columns

The values of the rows/columns indicate the amount of screen area each row/column will occupy

Page 38: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The Frame Tag

The <frame> tag defines what HTML document to put into each frame

<frameset cols="25%,75%">   <frame src="frame_a.htm">   <frame src="frame_b.htm"></frameset>

Page 39: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

In the example below we have a frameset with two columns. The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The HTML document "frame_a.htm" is put into the first column, and the HTML document "frame_b.htm" is put into the second column:

Page 40: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<frameset> Tag

Definition and Usage

The <frameset> tag defines a frameset.The frameset element holds two or more frame

elements. Each frame element holds a separate document.

The frameset element states only how many columns or rows there will be in the frameset.

Page 41: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

ExampleA simple three-framed page:<html>

<frameset cols="25%,*,25%">  <frame src="frame_a.htm" />  <frame src="frame_b.htm" />  <frame src="frame_c.htm" /></frameset>

</html>

Page 42: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Attributes COLS = PIXELS OR PERCENTAGESpecifies the number and size of columns in a

frameset

ROWS = PIXELS OR PERCENTAGESpecifies the number and size of rows in a

frameset

Page 43: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Vertical Frame<html>

<frameset cols="25%,50%,25%">

<frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm">

</frameset>

Page 44: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Horizontal Frame<html>

<frameset rows="25%,50%,25%">

<frame src="frame_a.htm"> <frame src="frame_b.htm"> <frame src="frame_c.htm"> </frameset>

Page 45: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<IMG>……..</IMG><AREA>……</AREA><MAP>………</MAP>

Page 46: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

The <img> tag embeds an image in an HTML page.

Notice that images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image.

The <img> tag has two required attributes: src and alt.

Page 47: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Required Attributes

Attribute Value Description alt text Specifies an alternate text for an image

src URL Specifies the URL of an image

Page 48: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Example:

<html><body><img src="D:\i.jpg.jpg"><img src="" alt="image is note display">

</body></html>

Page 49: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Optional Attributes

Align : Use styles instead Specifies the alignment of an image according to surrounding elements Values : left ,right

<img src="D:\image1.jpg" align ="right">

Page 50: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Border: Specifies the width of the border around an image Value: pixels

Height : Specifies the height of an image Value: pixels %

Width :Specifies the width of an image Value : pixels %

Page 51: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

vspace: Specifies the whitespace on top and bottom of

an image Value: pixel

hspace: Specifies the whitespace on left and right side of

an image Value : pixel

Page 52: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Example:<html><body><img src="D:\image2.jpg" border=15><img src="D:\image3.jpg" width=250 height=500 ><img src="D:\image4.jpg" hspace="200“ vspace="1000"> </body></html>

Page 53: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.
Page 54: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Table HTML Elements are:

<TABLE>…………….</TABLE><CAPTION>…………</CAPTION><TH>………………….</TH><TR>………………….</TR><TD>………………….</TD>

Page 55: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

TABLE ATTRIBUTE:ALIGN =LEFT, RIGHT, CENTERBGCOLOR=“#RRGGBB /COLORNAME”BORDER =VALUEBORDERCOLOR=“#RRGGBB /COLORNAME”CELLPANDDING=VALUECELLSPACING=VALUEHEIGHT= PERCENTWIDTH= PERCENTBACKGROUND= IMAGE

Page 56: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

CAPTION ATTRIBUTESALIGN ATTRIBUTE

ALIGN=LEFTALIGN=RIGHTALIGN=CENTERALIGN=TOPALIGN=BOTTOM

Page 57: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

<TR>,<TH>,<TD> ATTRIBUTES

ALIGN=LEFT / RIGHT / CENTERBACKGROUND=IMAGEBGCOLOR=“#RRGGBB”/COLORNAMEBORDERCOLOR =“#RRGGBB”/COLORNAMECOLSPAN=VALUEROWSPAN=VALUEHEIGHT=PERCENTWIDTH=PERCENTNOWRAP

Page 58: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.
Page 59: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

TopicsBackground and History of PHPInstallationComments in PHPVariablesConditionsLoopsFunctionsFile HandlingDatabase Handling (MySQL, MSSQL,

ODBC)

Page 60: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

BackgroundPersonal Home Page – C kind of scripts

written in Perl language, by Rasmus Lerdorf in 1995.

He called the language as PHP/FI – Personal Home Page / Forms Interpreter.

1997 Version 2.0 was releasedThen came 3.0, 4.0. They were called PHP

simplyRecent version is PHP 5.2.3

Page 61: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

InstallationApache server need to be installed firstThe config file for apache server will be

present in the conf folder under the apache installed directory

Set the DocumentRoot to the path where the PHP files will be stored

Install PHP. Point apache conf directory when it asks so and select the appropriate web server.

Move the PHP.ini file to C:\WNDOWS directory

Page 62: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

PHP CommentsAll php files are saved with extension .phpThe can be written in notepad or any text

editorSingle line comment

// this is single line commentMulti line comment

/*….This is a multi line comment */

Page 63: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Sample PHP<html><body><?php echo “hello”; ?></html>

The above program will display hello in the browser

Page 64: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

VariablesVariables start with a $ symbolVariables can contain _ or numbers or

alphabets$ should be followed by _ or alphabet and not

by a numberPHP is loosely typed language. There is no

strict data typingVariable can be assigned with any values

Page 65: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Conditions If else

if(condn) {….}elseif(condn) {….}else { ….}

Switch caseswitch(var){case c1: statements;break..Default: statements; break;}

Page 66: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

LoopsFor

for(intialisation;condition;increment/decrement){ statements }

While while(condn) { ….}

Do Whiledo {….} while(condn);

Page 67: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Functions and ParametersPHP functions need to be defined with key

word functionIt can have zero or more values (parameters)Functions may or may not return valuesIf a function need to return value, the last

statement of the function should be returnreturn value;

Page 68: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

FunctionsParameter less function

<?php function sayHi(){

echo “hi”;}?> This can be called as <?php sayHi(); ?> in the

program

Page 69: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

FunctionsParameterized function<?php function greet($name){

echo “Hello “ . $name;}?>This can be called <?php greet(‘Ram’);?> This gives an output Hello Ram

Page 70: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

FunctionsFunction returning value<?phpfunction add($a,$b){

return ($a + $b);}?> When called like <?php echo add(1,2);?>

we will get an output 3 in the browser.

Page 71: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

File HandlingThis involves 5 tasks

Opening a fileReading data from a fileDisplaying the read dataWriting contents to another fileClosing a file

Page 72: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Opening a file$fp = fopen(‘filename’,’mode’);Eg $fp = fopen(‘c:\abc.txt’,’r’);

This opens a file abc.txt in read only modeAvailable modes:

r – read onlyw – write onlyw+ - read writeA – append – adding to the end

Page 73: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Reading a fileSeveral methods are available

fread(filepointer,no of bytes to read)fgetc(filepointer) – Reads character by characterfgets(filepointer) – Reads line by line

The read content can be stored in a variable$data = fread($fp,10) – this reads 10

characters from file pointed by file pointer $fp and stores in $data

If we want to read characters till end, we need to use a loop with condition checking for End of File

Page 74: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Writing to fileWe can use echo $data, to print the

contents read from the file to browserOr we can open another file in write mode

and put the contents to that file using either of these methodsfwrite(filepoiner,data);fputc(filepointer,char); - writes character by

characterfputs(filepointer,line); - writes line by line

Eg - fwrite($fpw,$data);

Page 75: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Closing a filefeof(fp) – Checks for end of file. Returns –1 if EOF is reached. Otherwise

returns 0To close a file use fclose(filepointer) methodEg. fclose($fp);

This closes the file pointed by $fp.

Page 76: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Database HandlingPHP can connect to

MySQLMSSQLAccess and other databases like oracle, postgre

sql etcThere are separate methods available for

connecting to the databases

Page 77: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

MySQL and MSSQL Connectionmysql_connect(dbserver,userid,password)mssql_connect(dbserver,userid,password)

These methods are used for connecting to MySQL and MSSQL server using a userid and password

$con = mysql_connect(‘localhost’,’root’,’root’);This gets a connection to the local mysql server

using the credentials root and rootIf server cannot be connected, it will throw an

error stating the problemNote: Mysql and MSSQL can be accessed in

identical way except for the preceeding mysql or mssql. So will use mysql henceforth.

Page 78: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

MySQL Select DBmysql_select_db(connection,dbname)

mysql_select_db($con,”test”);This will select the db test under the server localhost

If unable to select the database, an error will be thrown

Page 79: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

MySQL Execute Querymysql_query(connection,sql statement);This will execute the sql statement on the

database and store the result in a variableEg

$rs = mysql_query($con,select stmt);The rows of select statement will be stored in $rs$row = mysql_fetch_array($rs);

This will fetch a row and store in $row Values can be accessed like - $row[“ID”] – returns value

of column ID in the fetched row.

Page 80: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

MySQL and MSSQL CloseTo close a db connection we have close

methodmysql_close(connection);mssql_close(connection);

Examplemysql_close($con);mssql_close($con);

Page 81: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

ODBC Data handlingConnect to a data source

odbc_connect(dsn,uname,pwd);DSN – Data Source NameGo to Control Panel -> Administrative Tools ->

Datasources (ODBC)Click on ODBC and select System DSN tab.Click Add and choose Access Database (mdb)

and click FinishIn the dialog that appears, give DSN Name and

Description

Page 82: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

ODBC Data handling Contd..

Click on Select under Database sectionChoose a mdb (access database file) and give

OK

$conn=odbc_connect('nwind','','');Here nwind is the DSN that we have created in

our system to access a databaseWe have not given any user name or password

during DSN creationSo those fields are left empty.

Page 83: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Selecting rows from a table$rs = odbc_exec($conn,$sql);

$conn – connection string$sql – SQL query to select rows from table$rs is the result set of the query execution

odbc_fetch_row($rs)This command fetches row by row from the result

set$cid = odbc_result($rs,"CustomerID");

This command fetches value for the column CustomerID from the current row and stores it in the variable $cid.

Page 84: CREATED BY : VIRAL M.KORADIYA. Anchor elements are defined by the element. The element accepts several attributes, but either the Name or HREF attribute.

Closing Connectionodbc_close(connection)

This function closes the connection obtained and releases the same to the connection pool

odbc_close($conn);The connection defined by $conn is released

and no query can be executed using this connection variable hence forth.


Recommended