SlideShare a Scribd company logo
1 of 24
Database
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CREATE DATABASE testdb;  CREATE TABLE `symbols`  (      `id` int(11) NOT NULL auto_increment,      `country` varchar(255) NOT NULL default '',      `animal` varchar(255) NOT NULL default '',      PRIMARY KEY  (`id`)  )  INSERT INTO `symbols` VALUES (1, 'America', 'eagle');  INSERT INTO `symbols` VALUES (2, 'China', 'dragon');  INSERT INTO `symbols` VALUES (3, 'England', 'lion');  INSERT INTO `symbols` VALUES (4, 'India', 'tiger');  INSERT INTO `symbols` VALUES (5, 'Australia', 'kangaroo');  INSERT INTO `symbols` VALUES (6, 'Norway', 'elk');  FROM My SQL
Retrieve data from My Sql Database in PHP <?php  // set database server access variables:  $host  =  &quot;localhost&quot; ;  $user  =  &quot;test&quot; ;  $pass  =  &quot;test&quot; ;  $db  =  &quot;testdb&quot; ;  // open connection  $connection  =  mysql_connect ( $host ,  $user ,  $pass ) or die ( &quot;Unable to connect!&quot; );  // select database  mysql_select_db ( $db ) or die ( &quot;Unable to select database!&quot; );  // create query  $query  =  &quot;SELECT * FROM symbols&quot; ;  // execute query  $result  =  mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ());  Cont …
// see if any rows were returned  if ( mysql_num_rows ( $result ) >  0 ) {       // yes      // print them one after another       echo  &quot;<table cellpadding=10 border=1>&quot; ;      while( $row  =  mysql_fetch_row ( $result )) {          echo  &quot;<tr>&quot; ;          echo  &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;          echo  &quot;<td>&quot;  .  $row [ 1 ]. &quot;</td>&quot; ;          echo  &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;          echo  &quot;</tr>&quot; ;      }      echo  &quot;</table>&quot; ;  }  else {       // no      // print status message       echo  &quot;No rows found!&quot; ;  }  // free result set memory  mysql_free_result ( $result );  // close connection  mysql_close ( $connection );  ?>
OUTPUT
mysql_fetch_array()  Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.  mysql_fetch_row()  returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc()  returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead.  mysql_fetch_assoc()  is equivalent to calling  mysql_fetch_array()  with MYSQL_ASSOC for the optional second parameter. It only returns an associative array.  mysql_fetch_object()  returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.
mysql_fetch_array() <?php  $host  =  &quot;localhost&quot; ;  $user  =  &quot;root&quot; ;  $pass  =  &quot;guessme&quot; ;  $db  =  &quot;testdb&quot; ;  $connection  =  mysql_connect ( $host ,  $user ,  $pass ) or die ( &quot;Unable to connect!&quot; );  // get database list  $query  =  &quot;SHOW DATABASES&quot; ;  $result  =  mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ());  echo  &quot;<ul>&quot; ;  while ( $row  =  mysql_fetch_array ( $result )) {      echo  &quot;<li>&quot; . $row [ 0 ];       // for each database, get table list and print       $query2  =  &quot;SHOW TABLES FROM &quot; . $row [ 0 ];       $result2  =  mysql_query ( $query2 ) or die ( &quot;Error in query: $query2. &quot; . mysql_error ());      echo  &quot;<ul>&quot; ;      while ( $row2  =  mysql_fetch_array ( $result2 )) {          echo  &quot;<li>&quot; . $row2 [ 0 ];  }      echo  &quot;</ul>&quot; ;  }  echo  &quot;</ul>&quot; ;  // get version and host information  echo  &quot;Client version: &quot; . mysql_get_client_info (). &quot;<br />&quot; ;  echo  &quot;Server version: &quot; . mysql_get_server_info (). &quot;<br />&quot; ;  echo  &quot;Protocol version: &quot; . mysql_get_proto_info (). &quot;<br />&quot; ;  echo  &quot;Host: &quot; . mysql_get_host_info (). &quot;<br />&quot; ;  // get server status  $status  =  mysql_stat ();  echo  $status ;  // close connection  mysql_close ( $connection );  ?>
OUTPUT
mysql_fetch_row() // see if any rows were returned  if ( mysql_num_rows ( $result ) >  0 ) {        // yes       // print them one after another        echo  &quot;<table cellpadding=10 border=1>&quot; ;       while(list( $id ,  $country ,  $animal )  =  mysql_fetch_row ( $result )) {            echo  &quot;<tr>&quot; ;            echo  &quot;<td>$id</td>&quot; ;            echo  &quot;<td>$country</td>&quot; ;            echo  &quot;<td>$animal</td>&quot; ;            echo  &quot;</tr>&quot; ;       }       echo  &quot;</table>&quot; ;  }  else {        // no       // print status message        echo  &quot;No rows found!&quot; ;  }   OUTPUT
mysql_fetch_assoc() // see if any rows were returned  if ( mysql_num_rows ( $result ) >  0 ) {       // yes      // print them one after another       echo  &quot;<table cellpadding=10 border=1>&quot; ;      while( $row  =  mysql_fetch_assoc ( $result )) {          echo  &quot;<tr>&quot; ;          echo  &quot;<td>&quot; . $row [ 'id' ]. &quot;</td>&quot; ;          echo  &quot;<td>&quot; . $row [ 'country' ]. &quot;</td>&quot; ;          echo  &quot;<td>&quot; . $row [ 'animal' ]. &quot;</td>&quot; ;          echo  &quot;</tr>&quot; ;      }      echo  &quot;</table>&quot; ;  }  else {       // no      // print status message       echo  &quot;No rows found!&quot; ;  }   OUTPUT
mysql_fetch_object() // see if any rows were returned  if ( mysql_num_rows ( $result ) >  0 ) {       // yes      // print them one after another       echo  &quot;<table cellpadding=10 border=1>&quot; ;      while( $row   =  mysql_fetch_object ( $result )) {          echo  &quot;<tr>&quot; ;          echo  &quot;<td>&quot; . $row -> id . &quot;</td>&quot; ;          echo  &quot;<td>&quot; . $row -> country . &quot;</td>&quot; ;          echo  &quot;<td>&quot; . $row -> animal . &quot;</td>&quot; ;          echo  &quot;</tr>&quot; ;      }      echo  &quot;</table>&quot; ;  }  else {       // no      // print status message       echo  &quot;No rows found!&quot; ;  }   OUTPUT
Form application in php and mysql database <html>  <head>  <basefont face=&quot;Arial&quot;>  </head>  <body>  <?php  if (!isset( $_POST [ 'submit' ])) {  // form not submitted  ?>      <form action=&quot; <?=$_SERVER [ 'PHP_SELF' ] ?> &quot; method=&quot;post&quot;>      Country: <input type=&quot;text&quot; name=&quot;country&quot;>      National animal: <input type=&quot;text&quot; name=&quot;animal&quot;>      <input type=&quot;submit&quot; name=&quot;submit&quot;>      </form>   Cont …
<?php  }  else {  // form submitted  // set server access variables       $host  =  &quot;localhost&quot; ;       $user  =  &quot;test&quot; ;       $pass  =  &quot;test&quot; ;       $db  =  &quot;testdb&quot; ;        // get form input      // check to make sure it's all there      // escape input values for greater safety       $country  = empty( $_POST [ 'country' ]) ?  die ( &quot;ERROR: Enter a country&quot; ) :  mysql_escape_string ( $_POST [ 'country' ]);       $animal  = empty( $_POST [ 'animal' ]) ?  die ( &quot;ERROR: Enter an animal&quot; ) :  mysql_escape_string ( $_POST [ 'animal' ]);       // open connection       $connection  =  mysql_connect ( $host ,  $user ,  $pass ) or die ( &quot;Unable to connect!&quot; );   Cont …
// select database       mysql_select_db ( $db ) or die ( &quot;Unable to select database!&quot; );             // create query       $query  =  &quot;INSERT INTO symbols (country, animal) VALUES ('$country', '$animal')&quot; ;             // execute query       $result  =  mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ());             // print message with ID of inserted record       echo  &quot;New record inserted with ID &quot; . mysql_insert_id ();             // close connection       mysql_close ( $connection );  }  ?>  </body>  </html>
OUTPUT
mysqli library <html>  <head>  <basefont face=&quot;Arial&quot;>  </head>  <body>  <?php  // set server access variables  $host  =  &quot;localhost&quot; ;  $user  =  &quot;test&quot; ;  $pass  =  &quot;test&quot; ;  $db  =  &quot;testdb&quot; ;  // create mysqli object  // open connection  $mysqli  = new  mysqli ( $host ,  $user ,  $pass ,  $db );  // check for connection errors  if ( mysqli_connect_errno ()) {      die( &quot;Unable to connect!&quot; );  }  // create query  $query  =  &quot;SELECT * FROM symbols&quot; ;
if ( $result  =  $mysqli -> query ( $query )) {       // see if any rows were returned       if ( $result -> num_rows  >  0 ) {           // yes          // print them one after another           echo  &quot;<table cellpadding=10 border=1>&quot; ;          while( $row  =  $result -> fetch_array ()) {              echo  &quot;<tr>&quot; ;              echo  &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;              echo  &quot;<td>&quot; . $row [ 1 ]. &quot;</td>&quot; ;              echo  &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;              echo  &quot;</tr>&quot; ;          }          echo  &quot;</table>&quot; ;      }      else {           // no          // print status message           echo  &quot;No rows found!&quot; ;   }       // free result set memory       $result -> close ();  }  else {       // print error message       echo  &quot;Error in query: $query. &quot; . $mysqli -> error ;  }  // close connection  $mysqli -> close ();  ?>  </body>  </html>
OUTPUT
Delete record from mysqli library <?php  // set server access variables  $host  =  &quot;localhost&quot; ;  $user  =  &quot;test&quot; ;  $pass  =  &quot;test&quot; ;  $db  =  &quot;testdb&quot; ;  // create mysqli object  // open connection  $mysqli  = new  mysqli ( $host ,  $user ,  $pass ,  $db );  // check for connection errors  if ( mysqli_connect_errno ()) {      die( &quot;Unable to connect!&quot; );  }  // if id provided, then delete that record  if (isset( $_GET [ 'id' ])) {  // create query to delete record       $query  =  &quot;DELETE FROM symbols WHERE id = &quot; . $_GET [ 'id' ];   Cont …
// execute query       if ( $mysqli -> query ( $query )) {       // print number of affected rows       echo  $mysqli -> affected_rows . &quot; row(s) affected&quot; ;      }      else {       // print error message       echo  &quot;Error in query: $query. &quot; . $mysqli -> error ;      }  }  // query to get records  $query  =  &quot;SELECT * FROM symbols&quot; ;   Cont …
// execute query  if ( $result  =  $mysqli -> query ( $query )) {       // see if any rows were returned       if ( $result -> num_rows  >  0 ) {           // yes          // print them one after another           echo  &quot;<table cellpadding=10 border=1>&quot; ;          while( $row  =  $result -> fetch_array ()) {              echo  &quot;<tr>&quot; ;              echo  &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;              echo  &quot;<td>&quot; . $row [ 1 ]. &quot;</td>&quot; ;              echo  &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;              echo  &quot;<td><a href=&quot; . $_SERVER [ 'PHP_SELF' ]. &quot;?id=&quot; . $row [ 0 ]. &quot;>Delete</a></td>&quot; ;              echo  &quot;</tr>&quot; ;          }      }       // free result set memory       $result -> close ();  }  else {       // print error message       echo  &quot;Error in query: $query. &quot; . $mysqli -> error ;  }  // close connection  $mysqli -> close ();  ?>
OUTPUT
THE END

More Related Content

What's hot

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First WidgetChris Wilcoxson
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Balázs Tatár
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with ExtbaseJochen Rau
 
Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死Kiwamu Okabe
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendFITC
 
Concern of Web Application Security
Concern of Web Application SecurityConcern of Web Application Security
Concern of Web Application SecurityMahmud Ahsan
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Rafael Dohms
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPVineet Kumar Saini
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHPVineet Kumar Saini
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Intro to #memtech PHP 2011-12-05
Intro to #memtech PHP   2011-12-05Intro to #memtech PHP   2011-12-05
Intro to #memtech PHP 2011-12-05Jeremy Kendall
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
Apache Solr Search Mastery
Apache Solr Search MasteryApache Solr Search Mastery
Apache Solr Search MasteryAcquia
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Securitymussawir20
 

What's hot (20)

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
Views notwithstanding
Views notwithstandingViews notwithstanding
Views notwithstanding
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
 
Concern of Web Application Security
Concern of Web Application SecurityConcern of Web Application Security
Concern of Web Application Security
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Intro to #memtech PHP 2011-12-05
Intro to #memtech PHP   2011-12-05Intro to #memtech PHP   2011-12-05
Intro to #memtech PHP 2011-12-05
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
Apache Solr Search Mastery
Apache Solr Search MasteryApache Solr Search Mastery
Apache Solr Search Mastery
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 

Viewers also liked

Introduction to Computer Network
Introduction to Computer NetworkIntroduction to Computer Network
Introduction to Computer NetworkAdetula Bunmi
 
Week3 Lecture Database Design
Week3 Lecture Database DesignWeek3 Lecture Database Design
Week3 Lecture Database DesignKevin Element
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseSonali Parab
 
Importance of database design (1)
Importance of database design (1)Importance of database design (1)
Importance of database design (1)yhen06
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Processmussawir20
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapVikas Jagtap
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationEntity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationSatya Pal
 
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design processLearn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design processEduonix Learning Solutions
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 

Viewers also liked (18)

Introduction to Computer Network
Introduction to Computer NetworkIntroduction to Computer Network
Introduction to Computer Network
 
Normalization
NormalizationNormalization
Normalization
 
Week3 Lecture Database Design
Week3 Lecture Database DesignWeek3 Lecture Database Design
Week3 Lecture Database Design
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In DatabaseAdvance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
 
Fundamentals of Database Design
Fundamentals of Database DesignFundamentals of Database Design
Fundamentals of Database Design
 
Database design
Database designDatabase design
Database design
 
Database design
Database designDatabase design
Database design
 
Importance of database design (1)
Importance of database design (1)Importance of database design (1)
Importance of database design (1)
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
 
Advanced DBMS presentation
Advanced DBMS presentationAdvanced DBMS presentation
Advanced DBMS presentation
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalizationEntity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalization
 
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design processLearn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design process
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Basic DBMS ppt
Basic DBMS pptBasic DBMS ppt
Basic DBMS ppt
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
 

Similar to Php My Sql

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With PhpJeremy Coates
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Into to DBI with DBD::Oracle
Into to DBI with DBD::OracleInto to DBI with DBD::Oracle
Into to DBI with DBD::Oraclebyterock
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kianphelios
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Featuresfivespeed5
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstartguestfd47e4c7
 
PHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodPHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodJeremy Kendall
 
High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testingpetersergeant
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)Dennis Knochenwefel
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 
Secure Coding With Wordpress (BarCamp Orlando 2009)
Secure Coding With Wordpress (BarCamp Orlando 2009)Secure Coding With Wordpress (BarCamp Orlando 2009)
Secure Coding With Wordpress (BarCamp Orlando 2009)Mark Jaquith
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rulesnagarajhubli
 

Similar to Php My Sql (20)

PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Php 3 1
Php 3 1Php 3 1
Php 3 1
 
Into to DBI with DBD::Oracle
Into to DBI with DBD::OracleInto to DBI with DBD::Oracle
Into to DBI with DBD::Oracle
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
More Php
More PhpMore Php
More Php
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Features
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstart
 
PHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodPHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the Good
 
Ae internals
Ae internalsAe internals
Ae internals
 
High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testing
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Secure Coding With Wordpress (BarCamp Orlando 2009)
Secure Coding With Wordpress (BarCamp Orlando 2009)Secure Coding With Wordpress (BarCamp Orlando 2009)
Secure Coding With Wordpress (BarCamp Orlando 2009)
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rules
 

More from mussawir20

Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllersmussawir20
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operatorsmussawir20
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xmlmussawir20
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookiesmussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operationsmussawir20
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handlingmussawir20
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arraysmussawir20
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oopmussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)mussawir20
 

More from mussawir20 (20)

Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
Php Rss
Php RssPhp Rss
Php Rss
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Php Oop
Php OopPhp Oop
Php Oop
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oop
 
Html
HtmlHtml
Html
 
Javascript
JavascriptJavascript
Javascript
 
Object Range
Object RangeObject Range
Object Range
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
 
Date
DateDate
Date
 
Prototype js
Prototype jsPrototype js
Prototype js
 
Template
TemplateTemplate
Template
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Php My Sql

  • 2.
  • 3. CREATE DATABASE testdb; CREATE TABLE `symbols` (     `id` int(11) NOT NULL auto_increment,     `country` varchar(255) NOT NULL default '',     `animal` varchar(255) NOT NULL default '',     PRIMARY KEY  (`id`) ) INSERT INTO `symbols` VALUES (1, 'America', 'eagle'); INSERT INTO `symbols` VALUES (2, 'China', 'dragon'); INSERT INTO `symbols` VALUES (3, 'England', 'lion'); INSERT INTO `symbols` VALUES (4, 'India', 'tiger'); INSERT INTO `symbols` VALUES (5, 'Australia', 'kangaroo'); INSERT INTO `symbols` VALUES (6, 'Norway', 'elk'); FROM My SQL
  • 4. Retrieve data from My Sql Database in PHP <?php // set database server access variables: $host = &quot;localhost&quot; ; $user = &quot;test&quot; ; $pass = &quot;test&quot; ; $db = &quot;testdb&quot; ; // open connection $connection = mysql_connect ( $host , $user , $pass ) or die ( &quot;Unable to connect!&quot; ); // select database mysql_select_db ( $db ) or die ( &quot;Unable to select database!&quot; ); // create query $query = &quot;SELECT * FROM symbols&quot; ; // execute query $result = mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ()); Cont …
  • 5. // see if any rows were returned if ( mysql_num_rows ( $result ) > 0 ) {      // yes     // print them one after another      echo &quot;<table cellpadding=10 border=1>&quot; ;     while( $row = mysql_fetch_row ( $result )) {         echo &quot;<tr>&quot; ;         echo &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row [ 1 ]. &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;         echo &quot;</tr>&quot; ;     }     echo &quot;</table>&quot; ; } else {      // no     // print status message      echo &quot;No rows found!&quot; ; } // free result set memory mysql_free_result ( $result ); // close connection mysql_close ( $connection ); ?>
  • 7. mysql_fetch_array() Returns an array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_row() returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc() returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array. mysql_fetch_object() returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.
  • 8. mysql_fetch_array() <?php $host = &quot;localhost&quot; ; $user = &quot;root&quot; ; $pass = &quot;guessme&quot; ; $db = &quot;testdb&quot; ; $connection = mysql_connect ( $host , $user , $pass ) or die ( &quot;Unable to connect!&quot; ); // get database list $query = &quot;SHOW DATABASES&quot; ; $result = mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ()); echo &quot;<ul>&quot; ; while ( $row = mysql_fetch_array ( $result )) {     echo &quot;<li>&quot; . $row [ 0 ];      // for each database, get table list and print      $query2 = &quot;SHOW TABLES FROM &quot; . $row [ 0 ];      $result2 = mysql_query ( $query2 ) or die ( &quot;Error in query: $query2. &quot; . mysql_error ());     echo &quot;<ul>&quot; ;     while ( $row2 = mysql_fetch_array ( $result2 )) {         echo &quot;<li>&quot; . $row2 [ 0 ]; }     echo &quot;</ul>&quot; ; } echo &quot;</ul>&quot; ; // get version and host information echo &quot;Client version: &quot; . mysql_get_client_info (). &quot;<br />&quot; ; echo &quot;Server version: &quot; . mysql_get_server_info (). &quot;<br />&quot; ; echo &quot;Protocol version: &quot; . mysql_get_proto_info (). &quot;<br />&quot; ; echo &quot;Host: &quot; . mysql_get_host_info (). &quot;<br />&quot; ; // get server status $status = mysql_stat (); echo $status ; // close connection mysql_close ( $connection ); ?>
  • 10. mysql_fetch_row() // see if any rows were returned if ( mysql_num_rows ( $result ) > 0 ) {       // yes      // print them one after another       echo &quot;<table cellpadding=10 border=1>&quot; ;      while(list( $id , $country , $animal )  = mysql_fetch_row ( $result )) {           echo &quot;<tr>&quot; ;           echo &quot;<td>$id</td>&quot; ;           echo &quot;<td>$country</td>&quot; ;           echo &quot;<td>$animal</td>&quot; ;           echo &quot;</tr>&quot; ;      }      echo &quot;</table>&quot; ; } else {       // no      // print status message       echo &quot;No rows found!&quot; ; } OUTPUT
  • 11. mysql_fetch_assoc() // see if any rows were returned if ( mysql_num_rows ( $result ) > 0 ) {      // yes     // print them one after another      echo &quot;<table cellpadding=10 border=1>&quot; ;     while( $row = mysql_fetch_assoc ( $result )) {         echo &quot;<tr>&quot; ;         echo &quot;<td>&quot; . $row [ 'id' ]. &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row [ 'country' ]. &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row [ 'animal' ]. &quot;</td>&quot; ;         echo &quot;</tr>&quot; ;     }     echo &quot;</table>&quot; ; } else {      // no     // print status message      echo &quot;No rows found!&quot; ; } OUTPUT
  • 12. mysql_fetch_object() // see if any rows were returned if ( mysql_num_rows ( $result ) > 0 ) {      // yes     // print them one after another      echo &quot;<table cellpadding=10 border=1>&quot; ;     while( $row   = mysql_fetch_object ( $result )) {         echo &quot;<tr>&quot; ;         echo &quot;<td>&quot; . $row -> id . &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row -> country . &quot;</td>&quot; ;         echo &quot;<td>&quot; . $row -> animal . &quot;</td>&quot; ;         echo &quot;</tr>&quot; ;     }     echo &quot;</table>&quot; ; } else {      // no     // print status message      echo &quot;No rows found!&quot; ; } OUTPUT
  • 13. Form application in php and mysql database <html> <head> <basefont face=&quot;Arial&quot;> </head> <body> <?php if (!isset( $_POST [ 'submit' ])) { // form not submitted ?>     <form action=&quot; <?=$_SERVER [ 'PHP_SELF' ] ?> &quot; method=&quot;post&quot;>     Country: <input type=&quot;text&quot; name=&quot;country&quot;>     National animal: <input type=&quot;text&quot; name=&quot;animal&quot;>     <input type=&quot;submit&quot; name=&quot;submit&quot;>     </form> Cont …
  • 14. <?php } else { // form submitted // set server access variables      $host = &quot;localhost&quot; ;      $user = &quot;test&quot; ;      $pass = &quot;test&quot; ;      $db = &quot;testdb&quot; ;      // get form input     // check to make sure it's all there     // escape input values for greater safety      $country = empty( $_POST [ 'country' ]) ? die ( &quot;ERROR: Enter a country&quot; ) : mysql_escape_string ( $_POST [ 'country' ]);      $animal = empty( $_POST [ 'animal' ]) ? die ( &quot;ERROR: Enter an animal&quot; ) : mysql_escape_string ( $_POST [ 'animal' ]);      // open connection      $connection = mysql_connect ( $host , $user , $pass ) or die ( &quot;Unable to connect!&quot; ); Cont …
  • 15. // select database      mysql_select_db ( $db ) or die ( &quot;Unable to select database!&quot; );           // create query      $query = &quot;INSERT INTO symbols (country, animal) VALUES ('$country', '$animal')&quot; ;           // execute query      $result = mysql_query ( $query ) or die ( &quot;Error in query: $query. &quot; . mysql_error ());           // print message with ID of inserted record      echo &quot;New record inserted with ID &quot; . mysql_insert_id ();           // close connection      mysql_close ( $connection ); } ?> </body> </html>
  • 17. mysqli library <html> <head> <basefont face=&quot;Arial&quot;> </head> <body> <?php // set server access variables $host = &quot;localhost&quot; ; $user = &quot;test&quot; ; $pass = &quot;test&quot; ; $db = &quot;testdb&quot; ; // create mysqli object // open connection $mysqli = new mysqli ( $host , $user , $pass , $db ); // check for connection errors if ( mysqli_connect_errno ()) {     die( &quot;Unable to connect!&quot; ); } // create query $query = &quot;SELECT * FROM symbols&quot; ;
  • 18. if ( $result = $mysqli -> query ( $query )) {      // see if any rows were returned      if ( $result -> num_rows > 0 ) {          // yes         // print them one after another          echo &quot;<table cellpadding=10 border=1>&quot; ;         while( $row = $result -> fetch_array ()) {             echo &quot;<tr>&quot; ;             echo &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;             echo &quot;<td>&quot; . $row [ 1 ]. &quot;</td>&quot; ;             echo &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;             echo &quot;</tr>&quot; ;         }         echo &quot;</table>&quot; ;     }     else {          // no         // print status message          echo &quot;No rows found!&quot; ;  }      // free result set memory      $result -> close (); } else {      // print error message      echo &quot;Error in query: $query. &quot; . $mysqli -> error ; } // close connection $mysqli -> close (); ?> </body> </html>
  • 20. Delete record from mysqli library <?php // set server access variables $host = &quot;localhost&quot; ; $user = &quot;test&quot; ; $pass = &quot;test&quot; ; $db = &quot;testdb&quot; ; // create mysqli object // open connection $mysqli = new mysqli ( $host , $user , $pass , $db ); // check for connection errors if ( mysqli_connect_errno ()) {     die( &quot;Unable to connect!&quot; ); } // if id provided, then delete that record if (isset( $_GET [ 'id' ])) { // create query to delete record      $query = &quot;DELETE FROM symbols WHERE id = &quot; . $_GET [ 'id' ]; Cont …
  • 21. // execute query      if ( $mysqli -> query ( $query )) {      // print number of affected rows      echo $mysqli -> affected_rows . &quot; row(s) affected&quot; ;     }     else {      // print error message      echo &quot;Error in query: $query. &quot; . $mysqli -> error ;     } } // query to get records $query = &quot;SELECT * FROM symbols&quot; ; Cont …
  • 22. // execute query if ( $result = $mysqli -> query ( $query )) {      // see if any rows were returned      if ( $result -> num_rows > 0 ) {          // yes         // print them one after another          echo &quot;<table cellpadding=10 border=1>&quot; ;         while( $row = $result -> fetch_array ()) {             echo &quot;<tr>&quot; ;             echo &quot;<td>&quot; . $row [ 0 ]. &quot;</td>&quot; ;             echo &quot;<td>&quot; . $row [ 1 ]. &quot;</td>&quot; ;             echo &quot;<td>&quot; . $row [ 2 ]. &quot;</td>&quot; ;             echo &quot;<td><a href=&quot; . $_SERVER [ 'PHP_SELF' ]. &quot;?id=&quot; . $row [ 0 ]. &quot;>Delete</a></td>&quot; ;             echo &quot;</tr>&quot; ;         }     }      // free result set memory      $result -> close (); } else {      // print error message      echo &quot;Error in query: $query. &quot; . $mysqli -> error ; } // close connection $mysqli -> close (); ?>