Your SlideShare is downloading. ×
0
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
P H P  Part  I I,  By  Kian
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

P H P Part I I, By Kian

4,770

Published on

Published in: Technology
4 Comments
13 Likes
Statistics
Notes
  • its very helpful for me, please email a copy of this at naresh2629@gmail.com

    thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • it very helpful to me
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • this ppt is concise and informative, can you also email a copy to me at
    billsfchan@yahoo.com
    thanks

    Bill
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • hello...this ppt is very useful for me,,,can u plz mail it to me at apratiks@gmail.com
    thanks
    pratiksha
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,770
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
4
Likes
13
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Inscribed By: Kian  PHP & MySQL & Dreamweaver
  • 2. PART II
    • Installation & Hands On Practice!
  • 3. Installations
    • Installing devphp package
    • Testing the Apache Server by applying PHP codes
    • Installing MySQL-Front
    • Installing an Editor (Crimson)
    • Installing a Designing Application Program (Dearmweaver)
  • 4. Testing PHP
    • Create the following hello.php script
    • Put it in C:phpdevwwwhello.php
    <html> <head><title>Hello Script</title></head> <body> <?php echo &quot;<h1>Hello PHP World!</h1>&quot; ?> (or <?php echo phpinfo(); ?>) </body> </html>
  • 5. Exercise: Creating A HTML Form
    • <html>
    • <head>A HTML Page!</head>
    • <body>
    • <b>Survey Form</b>
    • <form method = &quot;post&quot; action=“survey.php&quot;>
    • What is your name? <input name = &quot;Name&quot; type = &quot;text&quot;>
    • <br>
    • What is your age? <input name = &quot;Age&quot; type = &quot;text&quot;>
    • <br>
    • Which country are you from?
    • <select name = &quot;Country&quot;>
    • <option value = &quot;Malaysia&quot;>Malaysia</option>
    • <option value = &quot;Thailand&quot;>Thailand</option>
    • <option value = &quot;Singapore&quot;>Singapore</option>
    • <option value = &quot;Others&quot;>Others</option>
    • </select>
    • <br><br>
    • <input type=&quot;submit&quot; name=&quot;Submit&quot;>
    • </form></body></html>
    save as form.html
  • 6.  
  • 7.  
  • 8.  
  • 9. MySQL
    • Open source database.
    • Data & information
    • Data Types are:
      • char
      • varchar
      • int
      • text
      • float
      • date
      • time
  • 10.
    • mysql_connect(server, username, password)
      • connects to a MySQL server through a port
      • the default is the string &quot;localhost:3306&quot;
      • username is a string for the user name
      • password is a string for the password
      • returns TRUE on success else FALSE
    • $database = mysql_connect(&quot;localhost&quot;, “&quot;, &quot;&quot;)
    • Mysql_close(database_connection);
    Connecting To A Database
  • 11. MySQL Window Using MySQL Front
  • 12. SQL
    • SQL-Std Language for Interacting With most Databases. SQL commands can be divided into 2 main sub languages:
    • D ata D escription L anguage ( DDL ):
      • (Create, Alter, Drop)
    • D ata M anipulation L anguage ( DML ):
      • (Insert, Update ,Delete)
    • Data Retrieval:
      • (Select)
    • Join Statements:
      • (Join)
  • 13. MySQL & PHP
    • Sample PHP-MySQL application
    • Connect to MySQL database server
    • Send SQL query to MySQL server and get the results
    • Use the A pplication P rogramming I nterface’s ( API ) to get data from the result that is returned in step2
    • Generate an HTML page to display the contents
  • 14. MySQL API Support in PHP (PHP Functions for MySQL)
    • mysql_connect (server-name, user-name, password);
    • Attempts to open a connection to a MySQL server. Returns a link-identifier on success or false on failure.
    • mysql_create_db (database-name, link-identifier);
    • Attempts to create a new database on the server associated with the specified link-identifier. Returns true on success or false on failure.
    • mysql_select_db (database-name, link-identifier);
    • Select the current active database on the server that’s associated with the specified link-identifier. Returns true on success or false on failure.
  • 15. MySQL API Support in PHP (PHP Functions for MySQL)
    • mysql_drop_db (database-name, link-identifier);
    • Attempts to delete an entire database on the server associated with the specified link-identifier . Returns true on success or false on failure.
    • mysql_fetch_array (result-resource);
    • Returns an array that corresponds to a database table row or returns false if there are no more rows.
    • mysql_num_rows (result-resource);
    • Returns the number of table rows in a result-resource .
  • 16. MySQL API Support in PHP (PHP Functions for MySQL)
    • mysql_list_dbs (link-identifier);
    • Lists the databases available on a MySQL server.
    • mysql_list_tables (database-name, link-identifier);
    • Lists tables in the specified database.
    • mysql_query (SQL-query-string, link-identifier);
    • Sends a query to the currently active database on the server that’s associated with the specified link-identifier. Returns a result-resource answering the query on success or false on failure.
  • 17. MySQL API Support in PHP
    • Mysql_connect
    • int mysql_connect(string hostname,string username,string password)
    • eg $conn=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,“ &quot;);
  • 18.
    • Mysql_select_db
    • Int mysql_sellect_db(string database_name,int connection_identifier)
    • Eg mysql_select_db(&quot;studentdb&quot;,$conn);-returns true on success and false on failure
    • Mysql_query
    • Int mysql_query(string query)
    • Eg $result=mysql_query(&quot;SELECT * FROM students&quot;);
    • It contains the result of the execution of the query.
  • 19.
    • Mysql_num_rows
    • Int mysql_num_rows(int result)
    • It returns the number of rows in the result identifier.Eg $num_rows=mysql_num_rows($result);
    • Mysql_fetch_array
    • Fetches the row as an associative array
    • Array mysql_fetch_array(int result_identifier)
    • Eg $row=mysql_fetch_array($result)
  • 20.
    • Mysql_close
    • int mysql_close(int link_identifier)
    • mysql_close($conn)
  • 21. Connection
    • <?
    • $connection=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
    • if(!connection)
    • {
    • echo &quot;Unable to connect to the database server&quot;;
    • }
    • else
    • {
    • echo &quot;Connected&quot;;
    • }
    • ?>
  • 22. Connecting To Database
    • <?
    • mysql_select_db(&quot;studentdb&quot;,$connection);
    • echo &quot;Connected&quot;;
    • ?>
  • 23. Retrieving
    • <html>
    • <body>
    • <h1>Students Details</h1>
    • <table><tr><td>StudentId</td><td>StudentName</td><td>StudentPhone</td></tr>
    • <?
    • $conn=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
    • mysql_select_db(&quot;studentdb&quot;,$conn);
    • //echo &quot;connected&quot;;
    • $result=mysql_query(&quot;SELECT * FROM students&quot;);
    • $num_rows=mysql_num_rows($result);
    • if ($num_rows >0)
    • {
    • while($row=mysql_fetch_array($result))
      • {
    • $sid=$row[&quot;sid&quot;];
    • $sname=$row[&quot;sname&quot;];
    • $sphone=$row[&quot;sphone&quot;];
    • ?>
    • <tr><td><? echo $sid ?></td><td><? echo $sname ?></td><td><? echo “$sphone”; ?> </td>
    • <? } ?>
    • </tr></table>
    • <?
    • }
    • else { echo &quot;no Records found&quot;; mysql_close($conn); }
    • ?> </body> </html>
  • 24. Insert
    • <html>
    • <body>
    • <?
    • $conn=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
    • mysql_select_db(&quot;studentdb&quot;,$conn);
    • if($submit)
    • {
    • $sid=$_POST['sid'];
    • $sname=$_POST['sname'];
    • $sphone=$_POST['sphone'];
    • $sql=&quot;INSERT INTO students(sid,sname,sphone)VALUES('$sid','$sname','$sphone')&quot;;
    • mysql_query($sql);
    • echo &quot;Record Created&quot;;
    • }
    • ?>
    • <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;<? echo $PHP_SELF ?>&quot;>
    • StudentID:<input type=&quot;text&quot; name=&quot;sid&quot;><br>
    • StudentName:<input type=&quot;text&quot; name=&quot;sname&quot;><br>
    • Phone:<input type=&quot;text&quot; name=&quot;sphone&quot;><br>
    • <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Enter Information&quot;>
    • </form>
    • </body>
    • </html>
  • 25. A simple PHP class definition
    • Class IntStack
    • { /* a stack with type restricted to int */
    • var $the_stack;
    • var $count = 0;
    • function push ($intvar)
    • {
    • if (is_integer ($intvar))
    • {
    • $this->the_stack[$this->count] = $intvar; //put on stack
    • $this->count++; //increment count
    • print (“Push of $intvar succeeded.<BR>”);
    • }
    • else
    • print (“Hey, IntStack is for ints only!<BR>”);
    • }
    • function pop ()
    • {
    • if ($this->count>0)
    • {
    • $this->count--; //decrement count
    • $top = $this->the_stack[$this->count];
    • return ($top);
    • }
    • else
    • print (“Hey, the stack is empty!<BR>”);
    • }
    • }
  • 26. Exercise: PHP Action File
    • <?
    • $name= $_POST['Name'];
    • $age= $_POST['Age'];
    • $country= $_POST['Country'];
    • echo &quot;Hello, a person named $name has submitted the answer:<br>&quot;;
    • echo &quot;Name is :$name<br>&quot;;
    • echo &quot;Age is :$age<br>&quot;;
    • echo &quot; Country is :$country<br><br>&quot;;
    • if($country == 'Malaysia')
    • { echo &quot; I am Malaysian&quot;; }
    • else { echo &quot; I am not Malaysian&quot;; }
    • ?>
    save as survey.php
  • 27. PHP Sessions What is a Session ? Briefly a session is a unique id, to which we can store variables and can access over multiple pages.
    • Implementing a simple session
    • Starting a session session_start();
    • 2. Register session variables $_SESSION[‘ variable ] =‘VALUE’ ;
    • Using session variables $new_var= $_SESSION [‘ variable’ ];
    • Deregistering and destroying sessions
    • unset($_SESSION[‘variable’]) ; session_destroy();
  • 28. PHP Sessions (Example) <html><body> <? // 1. Start the session session_start(); $name = ‘Ali Hasan’ ; // 2. Register the variable $_SESSION[‘name’]=$name; echo ‘ <b> Page 1 ..</b>’; echo “name value=$name”; ?> <a href=‘Page2.php’> Go to Page 2 </a> </body></html> Page1.php <html><body> <? // 1. Start the session session_start(); $name=$_SESSION[‘name’]; echo ‘ <b> Page 2 ..</b>’; echo “name value=$name”; ?> <a href=‘Page3.php’> Go to Page 3 </a> </body></html> <html><body> <? // 1. Start the session session_start(); $name=$_SESSION[‘name’]; echo ‘ <b> Page 3 ..</b>’; echo “name value=$name”; ?> <a href=‘Page1.php’> Go to Page 1 </a> </body></html> Page2.php Page3.php

×