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

PPT
07 Php Mysql Update Delete
PPTX
15. CodeIgniter editarea inregistrarilor
PDF
Laravel, the right way - PHPConference 2016
PPTX
16. CodeIgniter stergerea inregistrarilor
DOCX
Html To JSP
PDF
Building scalable products with WordPress - WordCamp London 2018
PDF
Code igniter parameter passing techniques
PDF
Laravel the right way
07 Php Mysql Update Delete
15. CodeIgniter editarea inregistrarilor
Laravel, the right way - PHPConference 2016
16. CodeIgniter stergerea inregistrarilor
Html To JSP
Building scalable products with WordPress - WordCamp London 2018
Code igniter parameter passing techniques
Laravel the right way

What's hot (20)

PDF
Codeigniter : Custom Routing - Manipulate Uri
PPTX
Sins Against Drupal 2
PPTX
Drupal sins 2016 10-06
PDF
PPTX
System performance tuning
PDF
Jqeury ajax plugins
PDF
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
PPT
Clever Joomla! Templating Tips and Tricks
PPT
WordPress as a Content Management System
RTF
Documento
PDF
Pemrograman Web 8 - MySQL
PDF
前后端mvc经验 - webrebuild 2011 session
PPT
Slimme Joomla! Templating Tips en Truuks
PDF
FLOW3, Extbase & Fluid cook book
PDF
DB API Usage - How to write DBAL compliant code
PPTX
24. CodeIgniter simple login with sessions
DOCX
Latihan form login
PPT
Web Scraping with PHP
KEY
PHPConf-TW 2012 # Twig
Codeigniter : Custom Routing - Manipulate Uri
Sins Against Drupal 2
Drupal sins 2016 10-06
System performance tuning
Jqeury ajax plugins
Training in Asp.net mvc3 platform-apextgi,noidaAspnetmvc3 j query
Clever Joomla! Templating Tips and Tricks
WordPress as a Content Management System
Documento
Pemrograman Web 8 - MySQL
前后端mvc经验 - webrebuild 2011 session
Slimme Joomla! Templating Tips en Truuks
FLOW3, Extbase & Fluid cook book
DB API Usage - How to write DBAL compliant code
24. CodeIgniter simple login with sessions
Latihan form login
Web Scraping with PHP
PHPConf-TW 2012 # Twig
Ad

Similar to 06 Php Mysql Connect Query (20)

PDF
Dependency Injection
PPT
P H P Part I I, By Kian
PPT
Php MySql For Beginners
PDF
How to Create Login and Registration API in PHP.pdf
PDF
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
ZIP
Drupal Development (Part 2)
PPT
My sql presentation
DOC
Ex[1].3 php db connectivity
PPT
Database presentation
PDF
[WLDN] Supercharging word press development in 2018
PDF
Bag Of Tricks From Iusethis
PDF
Using php with my sql
PDF
Php summary
PPTX
chapter_Seven Database manipulation using php.pptx
PPT
Framework
PPT
SQL Injection in PHP
PPT
Php Data Objects
PPTX
PHP and Cassandra
KEY
Unit testing zend framework apps
Dependency Injection
P H P Part I I, By Kian
Php MySql For Beginners
How to Create Login and Registration API in PHP.pdf
Difference between mysql_fetch_array and mysql_fetch_assoc in PHP
Drupal Development (Part 2)
My sql presentation
Ex[1].3 php db connectivity
Database presentation
[WLDN] Supercharging word press development in 2018
Bag Of Tricks From Iusethis
Using php with my sql
Php summary
chapter_Seven Database manipulation using php.pptx
Framework
SQL Injection in PHP
Php Data Objects
PHP and Cassandra
Unit testing zend framework apps
Ad

More from Geshan Manandhar (20)

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

Recently uploaded (20)

PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
The various Industrial Revolutions .pptx
PDF
August Patch Tuesday
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Modernising the Digital Integration Hub
PDF
Architecture types and enterprise applications.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
STKI Israel Market Study 2025 version august
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPT
Geologic Time for studying geology for geologist
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
sustainability-14-14877-v2.pddhzftheheeeee
The various Industrial Revolutions .pptx
August Patch Tuesday
Enhancing emotion recognition model for a student engagement use case through...
Zenith AI: Advanced Artificial Intelligence
Modernising the Digital Integration Hub
Architecture types and enterprise applications.pdf
O2C Customer Invoices to Receipt V15A.pptx
1 - Historical Antecedents, Social Consideration.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
STKI Israel Market Study 2025 version august
Group 1 Presentation -Planning and Decision Making .pptx
Benefits of Physical activity for teenagers.pptx
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
A contest of sentiment analysis: k-nearest neighbor versus neural network
CloudStack 4.21: First Look Webinar slides
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Geologic Time for studying geology for geologist
Web Crawler for Trend Tracking Gen Z Insights.pptx
Module 1.ppt Iot fundamentals and Architecture

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.