0% found this document useful (0 votes)
77 views9 pages

Lab Manual 05 CSE 406 Integrated Design Project II

The document provides information about database and backend design for a project. It discusses database design, ER diagrams, installing and configuring XAMPP on Windows 10, connecting to MySQL using PHP, and performing CRUD operations like creating tables, inserting data, and fetching data. The document contains sections on database design, XAMPP installation, fixing Apache errors, an introduction to MySQL, CREATE, INSERT, and SELECT statements in MySQL, and connecting to a MySQL database with PHP code examples.

Uploaded by

afnan mafuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views9 pages

Lab Manual 05 CSE 406 Integrated Design Project II

The document provides information about database and backend design for a project. It discusses database design, ER diagrams, installing and configuring XAMPP on Windows 10, connecting to MySQL using PHP, and performing CRUD operations like creating tables, inserting data, and fetching data. The document contains sections on database design, XAMPP installation, fixing Apache errors, an introduction to MySQL, CREATE, INSERT, and SELECT statements in MySQL, and connecting to a MySQL database with PHP code examples.

Uploaded by

afnan mafuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Department of

Computer Science and Engineering

Title: Database and backend design for


the given project

Integrated Design Project II


CSE 406

Green University of Bangladesh


1 Objective(s)
• To understand database design

• To create database for your project

• To work with back-end development

2 Database Design
Database design is the organization of data according to a database model. The designer deter-
mines what data must be stored and how the data elements interrelate. With this information,
they can begin to fit the data to the database model. Database management system manages
the data accordingly.Database design involves classifying data and identifying interrelation-
ships. This theoretical representation of the data is called an ontology. The ontology is the
theory behind the database’s design.

2.1 ER Diagram
Database designs also include ER (entity-relationship model) diagrams. An ER diagram is a
diagram that helps to design databases in an efficient way. Attributes in ER diagrams are
usually modeled as an oval with the name of the attribute, linked to the entity or relationship
that contains the attribute. ER models are commonly used in information system design; for
example, they are used to describe information requirements and / or the types of information
to be stored in the database during the conceptual structure design phase.

Figure 1: Caption

© Dept. of Computer Science and Engineering, GUB


3 How to install XAMPP on Windows 10
To download and install XAMPP on Windows 10, use these steps:

1. Open Apache Friends website.

2. Click the Download button for the Windows version of XAMPP and save the file on your
computer.

3. Double-click the downloaded file to launch the installer.

4. Click the OK button.

5. Click the Next button.

6. Use the default installed location. (Or choose another folder to install the software in the
“Select a folder” field.)

4 How to configure XAMPP on Windows 10


The XAMPP Control Panel includes three main sections. In the Modules section, you will find
all the web services available. You can start each service by clicking the Start button. When
you start some of the services, including Apache and MySQL, on the right side, you’ll also see
the process ID (PID) number and TCP/IP port (Port) numbers that each service is using. For
example, by default, Apache uses TCP/IP port 80 and 443, while MySQL uses TCP/IP port
3306.
You can also click the Admin button to access the administration dashboard for each service
and verify that everything is working correctly.

Figure 2

© Dept. of Computer Science and Engineering, GUB


5 How to fix Apache not starting on XAMPP
The XAMPP installation is very straightforward, but Windows 10 sometimes may not allow
the Apache server to run. Usually, it’s because the World Wide Publishing Service is running
on port 80 on your computer, which also happens to be the default TCP/IP port that Apaches
uses on XAMPP

5.1 Change default Apache TCP/IP port


Instead of removing the World Wide Web Services, you can configure Apache to run on a
different TCP/IP port.
To change the Apache listening port on XAMPP, use the steps:

1. Open XAMPP Control Panel.

2. On Apache, click the Config button.

3. Select the Apache (httpd.conf) option.

4. Scroll down and find the line: Listen 80.

5. Change the number 80 for another TCP/IP port number that isn’t in use. For instance,
you can try port 81. (After the change, the line should read: Listen 81.)

Figure 3

6. Save and close the httpd.conf file.

7. Click the Start button on Apache from the XAMPP Control Panel.

Once you complete the steps, the Apache server should run without issues on the new TCP/IP
port specified. The only caveat with this configuration is that you’ll need to append the TCP/IP
port number on the address whenever you want to connect to your website. For example, to
access the Apache server on the web browser, you will need to type: “localhost:81/dashboard”
instead of “localhost/dashboard.”

© Dept. of Computer Science and Engineering, GUB


6 Introduction to MySQL
MySQL is an Oracle-backed open source relational database management system (RDBMS)
based on Structured Query Language (SQL). MySQL runs on virtually all platforms, including
Linux, UNIX and Windows. Although it can be used in a wide range of applications, MySQL
is most often associated with web applications and online publishing.
MySQL is an important component of an open source enterprise stack called LAMP. LAMP
is a web development platform that uses Linux as the operating system, Apache as the web
server, MySQL as the relational database management system and PHP as the object-oriented
scripting language. (Sometimes Perl or Python is used instead of PHP.)
Originally conceived by the Swedish company MySQL AB, MySQL was acquired by Sun
Microsystems in 2008 and then by Oracle when it bought Sun in 2010. Developers can use
MySQL under the GNU General Public License (GPL), but enterprises must obtain a commer-
cial license from Oracle.
Today, MySQL is the RDBMS behind many of the top websites in the world and count-
less corporate and consumer-facing web-based applications, including Facebook, Twitter and
YouTube.

6.1 Compatibility with other services


MySQL was designed to be compatible with other systems. It supports deployment in virtual-
ized environments, such as Amazon RDS for MySQL, Amazon RDS for MariaDB and Amazon
Aurora for MySQL. Users can transfer their data to a SQL Server database by using database
migration tools like AWS Schema Conversion Tool and the AWS Database Migration Service.
The database object semantics between SQL Server and MySQL are similar, but not iden-
tical. There are architectural differences that must be considered when migrating from SQL
Server to MySQL. In MySQL, there is no difference between a database and a schema, while
SQL Server treats the two as separate entities.
After a database and a table have been created, we can start adding data in them.Here are
some syntax rules to follow:

• The SQL query must be quoted in PHP

• String values inside the SQL query must be quoted

• Numeric values must not be quoted

• The word NULL must not be quoted

6.2 CREATE statement in MySQL


The CREATE DATABASE statement is used to create a new SQL database.

• CREATE DATABASE databasename;

The CREATE TABLE statement is used to create a new table in a database

• CREATE TABLE tablename ( column1 datatype, column2 datatype, column3 datatype,


.... );

© Dept. of Computer Science and Engineering, GUB


6.3 INSERT statement in MySQL
The INSERT INTO statement is used to add new records to a MySQL table:

• INSERT INTO tablename (column1, column2, column3,...) VALUES (value1, value2,


value3,...)

6.4 SELECT statement in MySQL


• The SELECT statement is used to select data from one or more tables:

• SELECT columnname(s) FROM tablename or

• we can use the * character to select ALL columns from a table:

• SELECT ∗ FROM tablename

7 Connection to MySQL with PHP


7.1 PHP code to connect MySQL
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

7.2 CREATE TABLE using PHP


<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

© Dept. of Computer Science and Engineering, GUB


}

// sql to create table


$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";

if ($conn->query($sql) === TRUE) {


echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

7.3 INSERT Data into database


<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)


VALUES (’John’, ’Doe’, ’[email protected]’)";

if ($conn->query($sql) === TRUE) {


echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

© Dept. of Computer Science and Engineering, GUB


7.4 Fetch and show data from database
<?php
$servername = "localhost";
$username = "root";
$password = "";
$databasename = "geeksforgeeks";

// CREATE CONNECTION
$conn = new mysqli($servername,
$username, $password, $databasename);

// GET CONNECTION ERRORS


if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// SQL QUERY
$query = "SELECT * FROM ‘Student Details‘;";

// FETCHING DATA FROM DATABASE


$result = $conn->query($query);

if ($result->num_rows > 0){


// OUTPUT DATA OF EACH ROW
while($row = $result->fetch_assoc())
{
echo "Roll No: " .
$row["Roll_No"]. " - Name: " .
$row["Name"]. " | City: " .
$row["City"]. " | Age: " .
$row["Age"]. "<br>";
}
}
else {
echo "0 results";
}

$conn->close();
?>

© Dept. of Computer Science and Engineering, GUB


8 Discussion & Conclusion
Based on the focused objective(s), to understand about database design and implement it using
PHP or any other server site language. Now we can use MySQL with PHP to our project.

9 Lab Task (Please implement yourself and show the out-


put to the instructor)
1. Create database using PHP

2. Perform various operation in server site using PHP

10 Policy
Copying from internet, classmate, seniors, or from any other source is strongly prohibited.
100% marks will be deducted if any such copying is detected.

© Dept. of Computer Science and Engineering, GUB

You might also like