PHP Mysql Tutorial - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Mysql Tutorial - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, March 25, 2017

PHP Mysql Tutorial



PHP MySql Tutorial





In this tutorial i will share how to use mysql and php.

Lets get start.

For Cpanel
Open Mysql Database And Create A New Database And Create a New Username and Password then set the username to Database And Give all privilages.
Now Open Your Phpmyadmin from cpanel then select database and create a new table which we use to store data.

In this tutorial i will create a table name login
And Columns are
id - int - 255 - Auto increment - primary key
name - text
password - text
email - text

For xampp:

Open http://localhost/phpmyadmin
And Create a new database and create the table same as which we created in for server.

Now Lets start How to insert,select,update,delete data from database.

Create Database Connection in PHP

Filename: connect.php

<?php
$server=”localhost”;
$username=”root”;
$password=”root”;
$database=”demo”;
$con=mysql_connect($server,$username,$password);

//this function is user to connect our server mysql it takes three parameters first is your server ,second is username and third parameter is password.

$con2=mysql_select_db($database,$con);

//this function is used to select our database. it takes two parameter first parameter is database name and second is the connection which we create to connect our server.
?>



Insert Operation

<?php
include ‘connect.php’;
//inclufe function is used to to include one file into other in php

$name=”sswebtricks”;
$email=”sswebtricks@gmail.com”;
$password=”pass@123”;

$qr=mysql_query(“INSERT INTO login (name,email,password) VALUES (‘$name’,’$email’,’$password’));

//mysql_query is function to write our query it takes one parameter which is our query it returns boolean type value true or false

If($qr)
{
echo “insert sucess”;
}
else
{
echo “failed”;
}
?>


Select Operation

<?php
include ‘connect.php’;
$name=”sswebtricks”;

$qr=mysql_query(“select * from login”);
$row=mysql_fetch_array($qr);

//mysql fetch array function is used to fetch fetch all the data from.database it takes one parameter which is our query and return array value .Here we only fetch single row .

echo $row[‘email’].”<br>”;
//print the email of name

//Now we fetch multiple rows
while($row2=mysql_fetch_array($qr))
{
  echo $row2[‘email’].”<br>”;
}

?>


Update Operation

<?php
include ‘connect.php’;
$name=”sswebtricks”;
$newemail=”sksanjeev362@gmail.com”;

$qr=mysql_query(“UPDATE login SET email='$newemail' WHERE name=’$name’");

// Above is updAte query

if(mysql_affected_rows>0)
{
echo “updated”;
}
else
{
echo “failed”;
}


//mysql affected rows check how many rows will affected with our query
?>

Delete Operation

<?php
include ‘connect.php’;
$name=”sswebtricks”;

$qr=mysql_query(“delete from login where name=’$name’”);

if($qr)
{
echo “ deleted”;
}
else
{
echo “failed”;
}
?>


8 comments:

  1. Nice info about Php it’s reallyhelpful…. If it possible share some more tutorials……….

    ReplyDelete
    Replies
    1. Thanks ! We will Keep Updating With More Tutorials.

      Delete
  2. Each department of CAD have specific programmes which, while completed could provide you with a recognisable qualification that could assist you get a job in anything design enterprise which you would really like.

    AutoCAD training in Noida

    AutoCAD training institute in Noida


    Best AutoCAD training institute in Noida

    ReplyDelete
  3. Best kitchen chimney installation and service in Faridabad
    When cooking with oil, you will see the fact that smoke usually receives emitted in case you often uses the identical oil. Typically, these form of eating places have today's hoods as well as exhaust fans.
    Visit here
    Kitchen Chimney Repair Service in Noida
    Kitchen Kitchen Chimney Repair Service in Vaishali
    Kitchen Kitchen Chimney Repair Service in indirapuram
    Kitchen Kitchen Chimney Repair Service in vasundhra
    Kitchen Kitchen Chimney Repair Service in faridabad

    ReplyDelete

Post Top Ad