Your SlideShare is downloading. ×
0
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Database Connection With Mysql
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Database Connection With Mysql

3,103

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,103
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP – Database connection with mysql Harit Kothari [email_address]
  • 2. Agenda <ul><li>Installation </li></ul><ul><li>service, port, Running through WAMP </li></ul><ul><li>Database creation </li></ul><ul><li>Table creation </li></ul><ul><li>mysqldump and mysqlimport utility </li></ul><ul><li>phpmyadmin utility </li></ul>
  • 3. Installation <ul><li>Download mysql database installation pack </li></ul><ul><li>Install it by following manual steps </li></ul><ul><li>Start mysql service by using appropriate menu </li></ul>
  • 4. service, port, Running through WAMP <ul><li>mysql runs as a OS service </li></ul><ul><li>This service provides access to database </li></ul><ul><li>To access, we require 2 parameters: </li></ul><ul><ul><li>Service host name </li></ul></ul><ul><ul><li>Port </li></ul></ul><ul><li>PHP supports many RDBMS </li></ul><ul><li>mysql is most suitable and famous with PHP </li></ul>
  • 5. Database &amp; Table creation <ul><li>Either use phpmyadmin to create / alter OR </li></ul><ul><li>Go to mysql prompt and execute as under: </li></ul><ul><ul><li>shell&gt;create database db_name </li></ul></ul><ul><ul><li>shell&gt;create table table_name (colname datatype [size] [, ....] constraints...) </li></ul></ul>
  • 6. Data source names / DSN <ul><li>Syntax: dbsyntax://username:password@protocol+hostspec/database </li></ul><ul><li>Where: </li></ul><ul><ul><li>dbsyntax represents RDBMS name </li></ul></ul><ul><ul><li>Username &amp; password of database user for authentication </li></ul></ul><ul><ul><li>Protocol is optional – e.g. TCP </li></ul></ul><ul><ul><li>Hostspec is hostname on which datbase service is running </li></ul></ul><ul><ul><li>Database is actual database name under dbsyntax </li></ul></ul>
  • 7. DSN Examples <ul><li>mysql:///webdb </li></ul><ul><li>mysql://localhost/webdb </li></ul><ul><li>mysql://bondview@localhost/webdb </li></ul><ul><li>mysql://bondview@tcp+localhost/webdb </li></ul><ul><li>mysql://bondview:007@localhost/webdb </li></ul>
  • 8. <ul><li>Syntax DataBase </li></ul><ul><li>Mysql MySQL </li></ul><ul><li>Pgsql PostgreSQL </li></ul><ul><li>Ibase InterBase </li></ul><ul><li>Msql Mini SQL </li></ul><ul><li>Mssql Microsoft SQL Server </li></ul><ul><li>oci8 Oracle 7/8/8i </li></ul><ul><li>Odbc ODBC </li></ul><ul><li>Sybase SyBase </li></ul><ul><li>Ifx Informix </li></ul><ul><li>Fbsql FrontBase </li></ul>
  • 9. Database connection <ul><li>$db = DB::connect(DSN [, options ]); </li></ul><ul><li>DB::isError($db) This will return if any error occurred while connecting to DataBase with DSN </li></ul><ul><li>Options are: </li></ul><ul><ul><li>persistent - Connection persists between accesses </li></ul></ul><ul><ul><li>optimize - What to optimize for </li></ul></ul><ul><ul><li>debug - Display debugging information </li></ul></ul>
  • 10. Mysqldump – Dumping DataBase <ul><li>A utility to dump database for backup or offline modification </li></ul><ul><li>A CLI utility that can be executed from SQL prompt to take regular backup of database / table as per requirements </li></ul>
  • 11. <ul><li>Ways to dump sql DB </li></ul><ul><ul><li>shell&gt; mysqldump [options] db_name [tables] </li></ul></ul><ul><ul><li>shell&gt; mysqldump [options] --databases db_name1 [db_name2 db_name3...] </li></ul></ul><ul><ul><li>shell&gt; mysqldump [options] --all-databases </li></ul></ul>
  • 12. Play with PHP <ul><li>Connect to database : mysql_connect(&amp;quot;host_name&amp;quot;, &amp;quot;db_username&amp;quot;, &amp;quot;db_password&amp;quot;); </li></ul><ul><li>Select Database : mysql_select_db(&amp;quot;db_name&amp;quot;); </li></ul>
  • 13. Mysqlimport – Import data <ul><li>Import database, by importing one oe more text files </li></ul><ul><li>Syntax: shell&gt; mysqlimport options db_name input_file </li></ul><ul><li>Useful especially while importing data from CSV files that contains data </li></ul>
  • 14. phpmyadmin <ul><li>Manage mysql database – an administration tool </li></ul><ul><li>Tool itself written in PHP to manage DataBase effectively and easily </li></ul><ul><li>Supports operations like create, modify, dump and delete database, table, views etc </li></ul><ul><li>Very easy to use, GUI </li></ul>
  • 15. Summary
  • 16. Whats next?

×