SlideShare a Scribd company logo
Database
PHP  support variety of database management systems, including : - MySQL - PostgreSQL - Oracle - Microsoft Access  MySQL very fast very reliable very feature-rich open-source RDBMS Every MySQL database is composed of : one or more  tables .  These tables, which: structure data into rows and columns,  are what lend organization to the data.
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 (20)

Building Your First Widget
Building Your First Widget
Chris Wilcoxson
 
Propel sfugmd
Propel sfugmd
iKlaus
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Balázs Tatár
 
Views notwithstanding
Views notwithstanding
Srikanth Bangalore
 
Current state-of-php
Current state-of-php
Richard McIntyre
 
Get into the FLOW with Extbase
Get into the FLOW with Extbase
Jochen Rau
 
Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死
Kiwamu Okabe
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
FITC
 
Concern of Web Application Security
Concern of Web Application Security
Mahmud Ahsan
 
Pagination in PHP
Pagination in PHP
Vineet Kumar Saini
 
Sorting arrays in PHP
Sorting arrays in PHP
Vineet Kumar Saini
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13
Rafael Dohms
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
Country State City Dropdown in PHP
Country State City Dropdown in PHP
Vineet Kumar Saini
 
Wsomdp
Wsomdp
riahialae
 
PHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Intro to #memtech PHP 2011-12-05
Intro to #memtech PHP 2011-12-05
Jeremy Kendall
 
2014 database - course 2 - php
2014 database - course 2 - php
Hung-yu Lin
 
Apache Solr Search Mastery
Apache Solr Search Mastery
Acquia
 
Php Basic Security
Php Basic Security
mussawir20
 
Building Your First Widget
Building Your First Widget
Chris Wilcoxson
 
Propel sfugmd
Propel sfugmd
iKlaus
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Balázs Tatár
 
Get into the FLOW with Extbase
Get into the FLOW with Extbase
Jochen Rau
 
Play, Slick, play2-authの間で討死
Play, Slick, play2-authの間で討死
Kiwamu Okabe
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
FITC
 
Concern of Web Application Security
Concern of Web Application Security
Mahmud Ahsan
 
Your code sucks, let's fix it! - php|tek13
Your code sucks, let's fix it! - php|tek13
Rafael Dohms
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
Country State City Dropdown in PHP
Country State City Dropdown in PHP
Vineet Kumar Saini
 
PHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Intro to #memtech PHP 2011-12-05
Intro to #memtech PHP 2011-12-05
Jeremy Kendall
 
2014 database - course 2 - php
2014 database - course 2 - php
Hung-yu Lin
 
Apache Solr Search Mastery
Apache Solr Search Mastery
Acquia
 
Php Basic Security
Php Basic Security
mussawir20
 

Viewers also liked (18)

Introduction to Computer Network
Introduction to Computer Network
Adetula Bunmi
 
Normalization
Normalization
Randy Riness @ South Puget Sound Community College
 
Week3 Lecture Database Design
Week3 Lecture Database Design
Kevin Element
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
Sonali Parab
 
Fundamentals of Database Design
Fundamentals of Database Design
Information Technology
 
Database design
Database design
Jennifer Polack
 
Database design
Database design
FLYMAN TECHNOLOGY LIMITED
 
Importance of database design (1)
Importance of database design (1)
yhen06
 
Database Design Process
Database Design Process
mussawir20
 
Advanced DBMS presentation
Advanced DBMS presentation
Hindustan Petroleum
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
Vikas Jagtap
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalization
Satya Pal
 
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design process
Eduonix Learning Solutions
 
Sql ppt
Sql ppt
Anuja Lad
 
Introduction to database
Introduction to database
Pongsakorn U-chupala
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Basic DBMS ppt
Basic DBMS ppt
dangwalrajendra888
 
Dbms slides
Dbms slides
rahulrathore725
 
Introduction to Computer Network
Introduction to Computer Network
Adetula Bunmi
 
Week3 Lecture Database Design
Week3 Lecture Database Design
Kevin Element
 
Advance Database Management Systems -Object Oriented Principles In Database
Advance Database Management Systems -Object Oriented Principles In Database
Sonali Parab
 
Importance of database design (1)
Importance of database design (1)
yhen06
 
Database Design Process
Database Design Process
mussawir20
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
Vikas Jagtap
 
Entity relationship diagram - Concept on normalization
Entity relationship diagram - Concept on normalization
Satya Pal
 
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design process
Eduonix Learning Solutions
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Ad

Similar to Php My Sql (20)

Database presentation
Database presentation
webhostingguy
 
Php MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
SQL -PHP Tutorial
SQL -PHP Tutorial
Information Technology
 
PHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
Adam Trachtenberg
 
P H P Part I I, By Kian
P H P Part I I, By Kian
phelios
 
Download It
Download It
webhostingguy
 
working with PHP & DB's
working with PHP & DB's
Hi-Tech College
 
More Php
More Php
Digital Insights - Digital Marketing Agency
 
Introtodatabase 1
Introtodatabase 1
Digital Insights - Digital Marketing Agency
 
Practical MySQL.pptx
Practical MySQL.pptx
HussainUsman4
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
John Coggeshall
 
Mysql
Mysql
lotlot
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
PHP with MySQL
PHP with MySQL
wahidullah mudaser
 
lab56_db
lab56_db
tutorialsruby
 
lab56_db
lab56_db
tutorialsruby
 
Diva10
Diva10
diva23
 
Ad

More from mussawir20 (20)

Php Operators N Controllers
Php Operators N Controllers
mussawir20
 
Php Calling Operators
Php Calling Operators
mussawir20
 
Php Simple Xml
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
Php String And Regular Expressions
mussawir20
 
Php Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Php Rss
Php Rss
mussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Php Oop
Php Oop
mussawir20
 
Php File Operations
Php File Operations
mussawir20
 
Php Error Handling
Php Error Handling
mussawir20
 
Php Crash Course
Php Crash Course
mussawir20
 
Php Using Arrays
Php Using Arrays
mussawir20
 
Javascript Oop
Javascript Oop
mussawir20
 
Html
Html
mussawir20
 
Javascript
Javascript
mussawir20
 
Object Range
Object Range
mussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Date
Date
mussawir20
 
Prototype js
Prototype js
mussawir20
 
Template
Template
mussawir20
 
Php Operators N Controllers
Php Operators N Controllers
mussawir20
 
Php Calling Operators
Php Calling Operators
mussawir20
 
Php Simple Xml
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
Php String And Regular Expressions
mussawir20
 
Php Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Php File Operations
Php File Operations
mussawir20
 
Php Error Handling
Php Error Handling
mussawir20
 
Php Crash Course
Php Crash Course
mussawir20
 
Php Using Arrays
Php Using Arrays
mussawir20
 
Javascript Oop
Javascript Oop
mussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 

Recently uploaded (20)

Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 

Php My Sql

  • 2. PHP support variety of database management systems, including : - MySQL - PostgreSQL - Oracle - Microsoft Access MySQL very fast very reliable very feature-rich open-source RDBMS Every MySQL database is composed of : one or more tables . These tables, which: structure data into rows and columns, are what lend organization to the data.
  • 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 (); ?>