0% found this document useful (0 votes)
16 views8 pages

PHP With Mysql

MySQL is a popular open-source relational database management system that is used by many large websites and content management systems. It can be used with PHP to build dynamic websites that retrieve and display data from the MySQL database. PHP connects to MySQL using extensions like MySQLi or PDO, which allow PHP code to execute SQL queries to get, insert, update and delete data in the MySQL database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

PHP With Mysql

MySQL is a popular open-source relational database management system that is used by many large websites and content management systems. It can be used with PHP to build dynamic websites that retrieve and display data from the MySQL database. PHP connects to MySQL using extensions like MySQLi or PDO, which allow PHP code to execute SQL queries to get, insert, update and delete data in the MySQL database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PHP with MySQL

What is MySQL?

MySQL is a relational database management system (RDBMS)


developed by Oracle that is based on structured query language
(SQL).
MySQL is a very popular open-source relational database management
system (RDBMS).
Characteristics
 MySQL is a relational database management system
 MySQL is open-source
 MySQL is free
 MySQL is ideal for both small and large applications
 MySQL is very fast, reliable, scalable, and easy to use
 MySQL is cross-platform
 MySQL is compliant with the ANSI SQL standard
 MySQL was first released in 1995
 MySQL is supported by Oracle Corporation
Who Uses MySQL?

 Huge websites like Facebook, Twitter, Airbnb, Booking.com, Uber,


GitHub, YouTube, etc.
 Content Management Systems like WordPress, Drupal, Joomla!,
Contao, etc.
 A very large number of web developers around the world
To build a web site that shows data
from a database, you will need:
• An RDBMS database program (like MySQL)
• A server-side scripting language, like PHP
• To use SQL to get the data you want
• To use HTML / CSS to style the page
PHP Connect to MySQL

 PHP 5 and later can work with a MySQL database using:


 MySQLi extension (the "i" stands for improved)
 PDO (PHP Data Objects)
 Earlier versions of PHP used the MySQL extension. However, this extension was
deprecated in 2012.
 <?php
$servername = "localhost";
$username = "username";
$password = "password";
$db = " my_db“;

// Create connection
$conn = mysqli_connect($servername, $username, $password, $my_db);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
<?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 Mytable (firstname, lastname, email)


VALUES (‘Ali', ‘Ahmed', '[email protected]')";

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


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

$conn->close();
?>

You might also like