SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
IELM 511 Information Systems Design
                        Labs 5 and 6. DB creation and Population

In this lab, your objective is to learn the basics of creating and managing a DB system. One
way to interact with the DBMS (MySQL) is to use the GUI provided by MySQL. However,
we shall use a separate interface, phpMyAdmin for most tasks in this lab and the next one.

Objectives of lab 5.
(a) Learn to create a database
(b) Learn to create tables in the database.

Objectives of lab 6.
(a) Learn to populate you DB tables.
(b) Learn the basics of developing a DB API using PHP CGI's.


As before, if you need to look up the syntax of some SQL command, you can use a good
online tutorial site, such as: http://www.w3schools.com/sql

Step 5.1. Create a DB using phpMyAdmin.
Before running this task, note that you should create a user account in MySQL, and assign
a password to the user. When you start phpMyAdmin, you will be presented with a screen
something like:




Use the link for "Create new database" to create a database called "bank".
After creating the database, click on the DB name, and then you can start creating tables.


Step 5.2. Create tables using phpMyAdmin.
You will learn three ways to create tables (two methods in lab 5, one in lab 6)
1. Using the GUI of phpMyAdmin program.
2. Using a SQL “CREATE TABLE …” command issued from phpMyAdmin GUI.
3. Using a CGI program to connect to your MySQL DB, and sending the command from
your CGI program

Before you create any table(s), please do your planning:

   - Names of all the tables.
   - All the attributes for each table
   - The domain constraint(s) for each attribute
   - The primary key for each table
   - The referential constraints (Foreign keys)

Conventions: Try to use a consistent convention for all names that you will assign.
For example:
All table names: First letter capitalized with no underscores: e.g. Loan.
All attribute names: lower case with underscores: name, ssn, start_date.
All constraint names: lower case, underscored; for example, a foreign key
constraints from in table Loan fk_loan_c1, etc.


1. How to use phpMyAdmin to create your own table?
1. Login in to phpMyAdmin, click on the database name on the left-hand-side
2. Enter the table name and number of fields, then click 'Go'.
3. For each attribute (field), enter the name and specify the type, length, set the
primary key, etc.; Click on “Save” to create the table.

Conventions: I suggest use only three data types: VARCHAR, DOUBLE and DATE.
Task: Use this method to create the 'Branch' table from your lecture notes.

2. How to use SQL command to create tables using phpMyAdmin
1. Click on the SQL tab (blue color) from any page of phpMyAdmin
2. Type your SQL command in a TXT file. Load the TXT file as below, and click 'Go'.


                                       bank                   localhost

       bank (-)




                  Type your SQL “create table ..” command in a TXT file.
                      Use this interface to load the query in this box




Task: Use this method to create all the tables of the 'bank' database from the lecture notes.



Step 6.1. Populate the tables using phpMyAdmin.
There are several ways to insert rows of data into a table:
1. Using the GUI provided by phpMyAdmin:
    - select the table
    - click on the "Insert" button, and
    - enter the data.
b_name char(30)
 city     char(60)

 assets double


                enter values here




2. The preferred way for this lab: Use the "insert into …" command of SQL, and type all
the store data commands into a TXT file3. Then load the file into the SQL interface and run
it.

3. It may be possible to import the data from some previously exported DB file (or even
from text or Excel files – however, you should not use that method for this lab.

Task: Use this method to populate all the tables you have created. For the tables in the lecture
notes, please use the same data as given (this will be later useful to test your homework
solutions!). For other tables, please use data consistent with the notes and the design.



Step 6.2. Learn the basics of developing a DB API using PHP CGI's.
In this lab, we will first learn the simplest method for a PHP program to connect to the
MySQL database. For now, you can use a modified version of the following PHP script,
and execute it directly from the phpDesigner (or compile it and run it from your local host.

NOTE: modify the portions that are in bold black.

    <?php
    $hostname = 'localhost';
    $username = 'root';
    $password = "password";

    $link = mysql_connect( $hostname, $username, $password ) or die("Could not
    connect : " . mysql_error());
    echo "Connected successfully!";

    $mydb = "dbname";
$db = mysql_select_db( $mydb ) or die("Could not select database");
   echo "Database " . $mydb . " selected.";

   // Note: values that are of type char( ) must be quoted; numbers are not in quotes.
   $query = "insert into mytable values( 'v1', 'v2', v3)";

   $result = mysql_query($query) or die("Query failed: " . mysql_error());

   /* $result is a special data structure; the function mysql_fetch_assoc is used to
      convert the returned table into a PHP associative array. */
   while ($row = mysql_fetch_assoc($result)) {
      echo $row['column_name_1'];
      echo $row['column_name_2'];
      echo $row['column_name_3'];
   }
   mysql_close($link);

   ?>


References:
1. HTML quick reference file.
2. PHP tutorials and function references: (from www.php.net)
3. PHP tutorial site: http://www.w3pop.com/learn/view/p/3/o/0/doc/php_ref_string/
4. Another PHP tutorial/reference: http://www.w3schools.com/PHP/php_ref_array.asp
5. MySQL tutorial/reference: http://www.w3schools.com/sql

Lab materials for IELM 511 prepared by WEI Xiangzhi, Dept of IELM, HKUST.

Weitere ähnliche Inhalte

Was ist angesagt? (19)

Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
PHP - Getting good with MySQL part II
 PHP - Getting good with MySQL part II PHP - Getting good with MySQL part II
PHP - Getting good with MySQL part II
 
MySQL
MySQLMySQL
MySQL
 
Php summary
Php summaryPhp summary
Php summary
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
PHP - PDO Objects
PHP - PDO ObjectsPHP - PDO Objects
PHP - PDO Objects
 
PHP with MySQL
PHP with MySQLPHP with MySQL
PHP with MySQL
 
MYSQL
MYSQLMYSQL
MYSQL
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014PDO Basics - PHPMelb 2014
PDO Basics - PHPMelb 2014
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 

Andere mochten auch

Jeni Intro1 Bab08 Argumen Dari Command Linei
Jeni Intro1 Bab08 Argumen Dari  Command LineiJeni Intro1 Bab08 Argumen Dari  Command Linei
Jeni Intro1 Bab08 Argumen Dari Command LineiIndividual Consultants
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 

Andere mochten auch (6)

PHP-Nuke-HOWTO
PHP-Nuke-HOWTOPHP-Nuke-HOWTO
PHP-Nuke-HOWTO
 
hw1a
hw1ahw1a
hw1a
 
Jeni Intro1 Bab08 Argumen Dari Command Linei
Jeni Intro1 Bab08 Argumen Dari  Command LineiJeni Intro1 Bab08 Argumen Dari  Command Linei
Jeni Intro1 Bab08 Argumen Dari Command Linei
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 

Ähnlich wie Create and populate MySQL DB using phpMyAdmin

Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySqlkamal kotecha
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08Terry Yoast
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxVinaOconner450
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxDIPESH30
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Shahrzad Peyman
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 

Ähnlich wie Create and populate MySQL DB using phpMyAdmin (20)

phptut4
phptut4phptut4
phptut4
 
phptut4
phptut4phptut4
phptut4
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
MySQL Presentation
MySQL PresentationMySQL Presentation
MySQL Presentation
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
Download It
Download ItDownload It
Download It
 
9780538745840 ppt ch08
9780538745840 ppt ch089780538745840 ppt ch08
9780538745840 ppt ch08
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
instaling
instalinginstaling
instaling
 
Php basics
Php basicsPhp basics
Php basics
 
My_sql_with_php
My_sql_with_phpMy_sql_with_php
My_sql_with_php
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 

Mehr von tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 

Mehr von tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
eng2u3less38
eng2u3less38eng2u3less38
eng2u3less38
 

Kürzlich hochgeladen

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Kürzlich hochgeladen (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Create and populate MySQL DB using phpMyAdmin

  • 1. IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population In this lab, your objective is to learn the basics of creating and managing a DB system. One way to interact with the DBMS (MySQL) is to use the GUI provided by MySQL. However, we shall use a separate interface, phpMyAdmin for most tasks in this lab and the next one. Objectives of lab 5. (a) Learn to create a database (b) Learn to create tables in the database. Objectives of lab 6. (a) Learn to populate you DB tables. (b) Learn the basics of developing a DB API using PHP CGI's. As before, if you need to look up the syntax of some SQL command, you can use a good online tutorial site, such as: http://www.w3schools.com/sql Step 5.1. Create a DB using phpMyAdmin. Before running this task, note that you should create a user account in MySQL, and assign a password to the user. When you start phpMyAdmin, you will be presented with a screen something like: Use the link for "Create new database" to create a database called "bank". After creating the database, click on the DB name, and then you can start creating tables. Step 5.2. Create tables using phpMyAdmin. You will learn three ways to create tables (two methods in lab 5, one in lab 6)
  • 2. 1. Using the GUI of phpMyAdmin program. 2. Using a SQL “CREATE TABLE …” command issued from phpMyAdmin GUI. 3. Using a CGI program to connect to your MySQL DB, and sending the command from your CGI program Before you create any table(s), please do your planning: - Names of all the tables. - All the attributes for each table - The domain constraint(s) for each attribute - The primary key for each table - The referential constraints (Foreign keys) Conventions: Try to use a consistent convention for all names that you will assign. For example: All table names: First letter capitalized with no underscores: e.g. Loan. All attribute names: lower case with underscores: name, ssn, start_date. All constraint names: lower case, underscored; for example, a foreign key constraints from in table Loan fk_loan_c1, etc. 1. How to use phpMyAdmin to create your own table? 1. Login in to phpMyAdmin, click on the database name on the left-hand-side 2. Enter the table name and number of fields, then click 'Go'.
  • 3. 3. For each attribute (field), enter the name and specify the type, length, set the primary key, etc.; Click on “Save” to create the table. Conventions: I suggest use only three data types: VARCHAR, DOUBLE and DATE. Task: Use this method to create the 'Branch' table from your lecture notes. 2. How to use SQL command to create tables using phpMyAdmin 1. Click on the SQL tab (blue color) from any page of phpMyAdmin 2. Type your SQL command in a TXT file. Load the TXT file as below, and click 'Go'. bank localhost bank (-) Type your SQL “create table ..” command in a TXT file. Use this interface to load the query in this box Task: Use this method to create all the tables of the 'bank' database from the lecture notes. Step 6.1. Populate the tables using phpMyAdmin. There are several ways to insert rows of data into a table: 1. Using the GUI provided by phpMyAdmin: - select the table - click on the "Insert" button, and - enter the data.
  • 4. b_name char(30) city char(60) assets double enter values here 2. The preferred way for this lab: Use the "insert into …" command of SQL, and type all the store data commands into a TXT file3. Then load the file into the SQL interface and run it. 3. It may be possible to import the data from some previously exported DB file (or even from text or Excel files – however, you should not use that method for this lab. Task: Use this method to populate all the tables you have created. For the tables in the lecture notes, please use the same data as given (this will be later useful to test your homework solutions!). For other tables, please use data consistent with the notes and the design. Step 6.2. Learn the basics of developing a DB API using PHP CGI's. In this lab, we will first learn the simplest method for a PHP program to connect to the MySQL database. For now, you can use a modified version of the following PHP script, and execute it directly from the phpDesigner (or compile it and run it from your local host. NOTE: modify the portions that are in bold black. <?php $hostname = 'localhost'; $username = 'root'; $password = "password"; $link = mysql_connect( $hostname, $username, $password ) or die("Could not connect : " . mysql_error()); echo "Connected successfully!"; $mydb = "dbname";
  • 5. $db = mysql_select_db( $mydb ) or die("Could not select database"); echo "Database " . $mydb . " selected."; // Note: values that are of type char( ) must be quoted; numbers are not in quotes. $query = "insert into mytable values( 'v1', 'v2', v3)"; $result = mysql_query($query) or die("Query failed: " . mysql_error()); /* $result is a special data structure; the function mysql_fetch_assoc is used to convert the returned table into a PHP associative array. */ while ($row = mysql_fetch_assoc($result)) { echo $row['column_name_1']; echo $row['column_name_2']; echo $row['column_name_3']; } mysql_close($link); ?> References: 1. HTML quick reference file. 2. PHP tutorials and function references: (from www.php.net) 3. PHP tutorial site: http://www.w3pop.com/learn/view/p/3/o/0/doc/php_ref_string/ 4. Another PHP tutorial/reference: http://www.w3schools.com/PHP/php_ref_array.asp 5. MySQL tutorial/reference: http://www.w3schools.com/sql Lab materials for IELM 511 prepared by WEI Xiangzhi, Dept of IELM, HKUST.