modimil

MySQL (Part 5)

May 1st, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. http://phpmysql-academy.blogspot.in/
  2.  
  3. Example: 1
  4.  
  5.  
  6. connection.php
  7.  
  8.     <?php
  9.  
  10.     error_reporting(0);
  11.     $connect = mysql_connect("localhost", "root", "admin") or die(mysql_error());
  12.  
  13.  
  14.     mysql_select_db("phpacademy1") or die(mysql_error());
  15.  
  16.     echo "Connected Succesfully!.<br><br>";
  17.  
  18.  
  19.     ?>
  20.  
  21.    
  22. Example: 2
  23.  
  24.  
  25. member.php
  26.  
  27.  
  28.     <?php
  29.  
  30.     session_start();
  31.  
  32.     if($_SESSION['username'])
  33.     echo "Welcome, " .$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br> ";
  34.     else
  35.     die ("You must be logged in!");
  36.  
  37.     ?>
  38.  
  39.  
  40.  
  41. Example 3
  42.  
  43.  
  44.  
  45. mysql.php
  46.  
  47.  
  48.     <?php
  49.     //connect include
  50.     require("connection.php");
  51.  
  52.     //write some data
  53.     //$date = date("Y-m-d");
  54.     //$write = mysql_query("INSERT INTO people1 VALUES ('','Muthu','Media','1985-03-15','M')");
  55.  
  56.  
  57.     //update data
  58.     //$update  = mysql_query("UPDATE people1 SET dob='1989-11-16' WHERE id='6'");
  59.  
  60.     //extract data
  61.     $extract = mysql_query("SELECT * FROM people1 ORDER BY id ASC") or die(mysql_error());
  62.     $numrows = mysql_num_rows($extract);
  63.  
  64.     echo "Last person to be inserted into table was....<br>";
  65.  
  66.     while ($row = mysql_fetch_assoc($extract))
  67.     {
  68.     $id        = $row['id'];
  69.     $firstname = $row['firstname'];
  70.     $lastname  = $row['lastname'];
  71.     $dob       = $row['dob'];
  72.     $gender    = $row['gender'];
  73.    
  74.    
  75.     echo "Text ";
  76.  
  77.     }
  78.  
  79.     ?>
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. Example 4
  87.  
  88.  
  89.     <?php
  90.     //connect include
  91.     require("connection.php");
  92.  
  93.     //write some data
  94.     //$date = date("Y-m-d");
  95.     //$write = mysql_query("INSERT INTO people1 VALUES ('','Muthu','Media','1985-03-15','M')");
  96.  
  97.  
  98.     //update data
  99.     //$update  = mysql_query("UPDATE people1 SET dob='1989-11-16' WHERE id='6'");
  100.  
  101.     //extract data
  102.     $extract = mysql_query("SELECT * FROM people1 ORDER BY id ASC") or die(mysql_error());
  103.     $numrows = mysql_num_rows($extract);
  104.  
  105.     echo "Last person to be inserted into table was....<br>";
  106.  
  107.     while ($row = mysql_fetch_assoc($extract))
  108.     {
  109.     $id        = $row['id'];
  110.     $firstname = $row['firstname'];
  111.     $lastname  = $row['lastname'];
  112.     $dob       = $row['dob'];
  113.     $gender    = $row['gender'];
  114.    
  115.     if ($gender=="F")
  116.         $gender = "Female";
  117.     else
  118.         $gender = "Male";
  119.    
  120.     echo "$firstname $lastname  was born $dob and is $gender  <br> ";
  121.  
  122.     }
  123.  
  124.     ?>
Advertisement
Add Comment
Please, Sign In to add comment