SlideShare a Scribd company logo
PHP Day 06 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com   http://www.php.net   http://www.mysql.com
PHP – MYSQL Functions  $resource_link =  mysql_connect  ( “server_name”, “user_name”, “password”); - Open a connection to a MySQL Server. mysql_select_db  ( “data_base_name”, $resourece_link ); - Select a MySQL database mysql_query  ( $query, $resourse_link); - Send a MySQL query to execute
PHP – MYSQL Functions mysql_fetch_row  ( resource $result ); - Get a result row as an enumerated array. mysql_fetch_array  ($result, RESULT_TYPE); - Fetch a result row as an associative array, a numeric array, or both. mysql_num_rows  ( resource $result ); - Get number of rows in result.
PHP – MYSQL Functions mysql_affected_rows  (); - Get number of affected rows in previous MySQL operation. mysql_error  ( $resource_link ); - Returns the text of the error message from previous MySQL operation. mysql_close  ( $resource_link ); - Close MySQL connection.
Insert the User form field values to tbl_users Assumed the form has been submitted with action insert_user_process and method post. db_conn.php <?php $db['host'] = &quot;localhost&quot;; $db['user_name'] = &quot;root&quot;; $db['pass_word'] = &quot;&quot;; $db['name'] = &quot;php_class_db&quot;; $connection = mysql_connect ($db['host'], $db['user_name'],$db['pass_word']); if(!$connection){ die(&quot;Error connecting to the database server&quot;); } $db_name = mysql_select_db($db['name'], $connection); ?>
User Table structure
The easy STATIC insert  “ INSERT INTO tbl_user_test ( user_login, pass_word, address, email, gender, heard_from, newsletter, created_on, modified_on )  VALUES ('&quot;.$fdata['user_login'].&quot;', '&quot;.$fdata['pass_word'].&quot;', '&quot;.$fdata['address'].&quot;', '&quot;.$fdata['email'].&quot;', '&quot;.$fdata['gender'].&quot;', '&quot;.$fdata['heard_from'].&quot;', '&quot;.$fdata['newsletter'].&quot;', '&quot;.$fdata['created_on'].&quot;', '&quot;.$fdata['modified_on'].&quot;');”;
Insert user function function insert_user_to_db($fdata){ global $connection; $tbl_name =&quot;tbl_user_test&quot;; //INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); $query = &quot;INSERT into $tbl_name (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= $key.&quot;)&quot;; } else{ $query .= $key.&quot;, &quot;; } }//could have done it with array_keys($fdata); … Continued
Insert user Function $query .= &quot; VALUES (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= &quot;'$value'&quot;.&quot;);&quot;; } else{ $query .= &quot;'$value'&quot;.&quot;, &quot;; } }   $result = mysql_query($query, $connection); if (!$result) { return 0; } else { return 1; }  } Full code at: day06\insert_user_process.php
Read some users from database
Function show users Code at day06\show_users.php
Output of show users
Questions
Upgrade your Login System Create database with db desiger4 and export with use of PHPMyAdmin. Authenticate a user to the login system user select * from $tbl_name where user_login = $fdata[‘user_login’]; Then compare password if it matches login else do not login. if($row[‘pass_word’] == $fdata[‘pass_word’]){ Login } Maintain session very well.

More Related Content

What's hot (20)

PDF
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
PPTX
Sins Against Drupal 2
Aaron Crosman
 
PPTX
Drupal sins 2016 10-06
Aaron Crosman
 
PDF
Fw1
priyaamal
 
PPTX
System performance tuning
Menandro Oba
 
PDF
Jqeury ajax plugins
Inbal Geffen
 
PDF
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
prav068
 
PPT
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
PPT
WordPress as a Content Management System
Valent Mustamin
 
RTF
Documento
Emersonjbn
 
PDF
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
PDF
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
PPT
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
PDF
FLOW3, Extbase & Fluid cook book
Bastian Waidelich
 
PDF
DB API Usage - How to write DBAL compliant code
Karsten Dambekalns
 
PPTX
24. CodeIgniter simple login with sessions
Razvan Raducanu, PhD
 
DOCX
Latihan form login
Edy Sinaga
 
PPT
Web Scraping with PHP
Matthew Turland
 
KEY
PHPConf-TW 2012 # Twig
Wake Liu
 
Codeigniter : Custom Routing - Manipulate Uri
Abdul Malik Ikhsan
 
Sins Against Drupal 2
Aaron Crosman
 
Drupal sins 2016 10-06
Aaron Crosman
 
System performance tuning
Menandro Oba
 
Jqeury ajax plugins
Inbal Geffen
 
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
prav068
 
Clever Joomla! Templating Tips and Tricks
ThemePartner
 
WordPress as a Content Management System
Valent Mustamin
 
Documento
Emersonjbn
 
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
前后端mvc经验 - webrebuild 2011 session
RANK LIU
 
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
FLOW3, Extbase & Fluid cook book
Bastian Waidelich
 
DB API Usage - How to write DBAL compliant code
Karsten Dambekalns
 
24. CodeIgniter simple login with sessions
Razvan Raducanu, PhD
 
Latihan form login
Edy Sinaga
 
Web Scraping with PHP
Matthew Turland
 
PHPConf-TW 2012 # Twig
Wake Liu
 

Similar to 06 Php Mysql Connect Query (20)

PDF
Dependency Injection
Rifat Nabi
 
PPT
P H P Part I I, By Kian
phelios
 
PPT
Php MySql For Beginners
Priti Solanki
 
PDF
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Vineet Kumar Saini
 
ZIP
Drupal Development (Part 2)
Jeff Eaton
 
PPT
My sql presentation
Nikhil Jain
 
DOC
Ex[1].3 php db connectivity
Mouli Chandira
 
PPT
Database presentation
webhostingguy
 
PDF
[WLDN] Supercharging word press development in 2018
Adam Tomat
 
PDF
Bag Of Tricks From Iusethis
Marcus Ramberg
 
PDF
Using php with my sql
salissal
 
PDF
Php summary
Michelle Darling
 
PPTX
chapter_Seven Database manipulation using php.pptx
Getawu
 
PPT
Framework
Nguyen Linh
 
PPT
SQL Injection in PHP
Dave Ross
 
PPT
Php Data Objects
hiren.joshi
 
PPTX
PHP and Cassandra
Dave Gardner
 
KEY
Unit testing zend framework apps
Michelangelo van Dam
 
Dependency Injection
Rifat Nabi
 
P H P Part I I, By Kian
phelios
 
Php MySql For Beginners
Priti Solanki
 
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Vineet Kumar Saini
 
Drupal Development (Part 2)
Jeff Eaton
 
My sql presentation
Nikhil Jain
 
Ex[1].3 php db connectivity
Mouli Chandira
 
Database presentation
webhostingguy
 
[WLDN] Supercharging word press development in 2018
Adam Tomat
 
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Using php with my sql
salissal
 
Php summary
Michelle Darling
 
chapter_Seven Database manipulation using php.pptx
Getawu
 
Framework
Nguyen Linh
 
SQL Injection in PHP
Dave Ross
 
Php Data Objects
hiren.joshi
 
PHP and Cassandra
Dave Gardner
 
Unit testing zend framework apps
Michelangelo van Dam
 
Ad

More from Geshan Manandhar (20)

PDF
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
PDF
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
PDF
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
PDF
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
PDF
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
PDF
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
PDF
Things i wished i knew as a junior developer
Geshan Manandhar
 
PDF
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
PDF
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
PDF
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
PDF
7 rules of simple and maintainable code
Geshan Manandhar
 
PDF
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
PDF
A simplified Gitflow
Geshan Manandhar
 
PDF
How to become a better software company technically
Geshan Manandhar
 
PDF
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
PDF
Message Queues a basic overview
Geshan Manandhar
 
PDF
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
PDF
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
PPTX
Git intro hands on windows with msysgit
Geshan Manandhar
 
ODP
Drupal 7 install with modules and themes
Geshan Manandhar
 
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
A simplified Gitflow
Geshan Manandhar
 
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Geshan Manandhar
 
Ad

Recently uploaded (20)

PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 

06 Php Mysql Connect Query

  • 1. PHP Day 06 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com http://www.php.net http://www.mysql.com
  • 2. PHP – MYSQL Functions $resource_link = mysql_connect ( “server_name”, “user_name”, “password”); - Open a connection to a MySQL Server. mysql_select_db ( “data_base_name”, $resourece_link ); - Select a MySQL database mysql_query ( $query, $resourse_link); - Send a MySQL query to execute
  • 3. PHP – MYSQL Functions mysql_fetch_row ( resource $result ); - Get a result row as an enumerated array. mysql_fetch_array ($result, RESULT_TYPE); - Fetch a result row as an associative array, a numeric array, or both. mysql_num_rows ( resource $result ); - Get number of rows in result.
  • 4. PHP – MYSQL Functions mysql_affected_rows (); - Get number of affected rows in previous MySQL operation. mysql_error ( $resource_link ); - Returns the text of the error message from previous MySQL operation. mysql_close ( $resource_link ); - Close MySQL connection.
  • 5. Insert the User form field values to tbl_users Assumed the form has been submitted with action insert_user_process and method post. db_conn.php <?php $db['host'] = &quot;localhost&quot;; $db['user_name'] = &quot;root&quot;; $db['pass_word'] = &quot;&quot;; $db['name'] = &quot;php_class_db&quot;; $connection = mysql_connect ($db['host'], $db['user_name'],$db['pass_word']); if(!$connection){ die(&quot;Error connecting to the database server&quot;); } $db_name = mysql_select_db($db['name'], $connection); ?>
  • 7. The easy STATIC insert “ INSERT INTO tbl_user_test ( user_login, pass_word, address, email, gender, heard_from, newsletter, created_on, modified_on ) VALUES ('&quot;.$fdata['user_login'].&quot;', '&quot;.$fdata['pass_word'].&quot;', '&quot;.$fdata['address'].&quot;', '&quot;.$fdata['email'].&quot;', '&quot;.$fdata['gender'].&quot;', '&quot;.$fdata['heard_from'].&quot;', '&quot;.$fdata['newsletter'].&quot;', '&quot;.$fdata['created_on'].&quot;', '&quot;.$fdata['modified_on'].&quot;');”;
  • 8. Insert user function function insert_user_to_db($fdata){ global $connection; $tbl_name =&quot;tbl_user_test&quot;; //INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); $query = &quot;INSERT into $tbl_name (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= $key.&quot;)&quot;; } else{ $query .= $key.&quot;, &quot;; } }//could have done it with array_keys($fdata); … Continued
  • 9. Insert user Function $query .= &quot; VALUES (&quot;; foreach($fdata as $key => $value){ if($key == &quot;modified_on&quot;){ $query .= &quot;'$value'&quot;.&quot;);&quot;; } else{ $query .= &quot;'$value'&quot;.&quot;, &quot;; } } $result = mysql_query($query, $connection); if (!$result) { return 0; } else { return 1; } } Full code at: day06\insert_user_process.php
  • 10. Read some users from database
  • 11. Function show users Code at day06\show_users.php
  • 12. Output of show users
  • 14. Upgrade your Login System Create database with db desiger4 and export with use of PHPMyAdmin. Authenticate a user to the login system user select * from $tbl_name where user_login = $fdata[‘user_login’]; Then compare password if it matches login else do not login. if($row[‘pass_word’] == $fdata[‘pass_word’]){ Login } Maintain session very well.