How to create DB connection and extract data using Mysqli

Data Base Connection and Extract data using PHP and MySqli

In this session, we will learn how to create a MySqli database connection & how to extract data using PHP and MySqli from PHPMyAdmin. We will go through video tutorials and Source Code below as the reference. Full Process - 1) First of all we need a PC/Laptop on windows or Linux. 2) we will do the setting of wamp server on a PC. We create the dynamic website using PHP and MySqli. Now, what is a dynamic website, Website which has to panel (i.e) Frontend for the users which has only viewing rights and the backend where the owner of the site has full rights to update or add a new post? 3) After successfully setting of wamp server we will try to connect our frontend with the database (In Php Myadmin) using MySqli Coding. 4) Before that, we have to create database and tables in our database with whom our frontend will form a uniform connection.



See below for full source code:- 

Now we describe our MySqli Coding step by step. Step 1 [$connect = mysqli_connect("localhost","root","","blog"); ] - We have created a connection between the page of the website with PhpMyadmin with the database "blog". Step 2 [$insert_query = "SELECT * from posts";] - WE are saying to select all the columns which are present in the table post. Step 3 [$run_query = mysqli_query($connect, $insert_query);] - we now running our query and saving it as $run_query. Step 4 [while($extract = mysqli_fetch_array($run_query)){] - we are running a while loop here so that the query can run till the selection of columns ends in the table posts. Step 5 [ $title = $extract["post_title"];] - we created a variable $title and save the value of post_title in it similarly we do the Step 6 and finally we print the output.

<?php
$connect = mysqli_connect("localhost","root","","blog");

$insert_query = "SELECT * from posts";
$run_query = mysqli_query($connect, $insert_query);
while($extract = mysqli_fetch_array($run_query)){
$title = $extract["post_title"];
$description  = $extract["post_desc"];
echo "<h1>$title</h1>";
}
?>

So after the creation of a connection between frontend and PHP MyAdmin, we are going to form a relation between the tables in a database "blog" named as "posts". We started extracting information from our database. We can do this both in Offline and Online Mode. In Offline Mode we have to download wamp server in our PC and after that, we have to save our website folder in www directory inside the www folder. we may run the source code by this way in an address bar of any browser LOCALHOST/name of the folder saved inside the www folder/. we can save our main page as index.php or index.html. we will work on MYSQLI (Latest version of Mysql). In Online mode, we should upload our main folder to the online server say Godaddy or Bigrock through FTP Software. On this case we will make some changes in our database connection such as  [$connect = mysqli_connect("localhost","username","password","blog"); ] username and password will be replaced with the respective username given by GoDaddy or whatever we have selected during setting of web server. DNS of the selected domain should be pointed to our web server to make our site live on the internet and we are ready to browse our website.

Video Tutorials:- 

We will go through video tutorials for the session (How to establish database connection using PHP and MySqli)




How to create DB connection and extract data using Mysqli

Data Base Connection and Extract data using PHP and MySqli

In this session, we will learn how to create a MySqli database connection & how to extract data using PHP and MySqli from PHPMyAdmin. We will go through video tutorials and Source Code below as the reference. Full Process - 1) First of all we need a PC/Laptop on windows or Linux. 2) we will do the setting of wamp server on a PC. We create the dynamic website using PHP and MySqli. Now, what is a dynamic website, Website which has to panel (i.e) Frontend for the users which has only viewing rights and the backend where the owner of the site has full rights to update or add a new post? 3) After successfully setting of wamp server we will try to connect our frontend with the database (In Php Myadmin) using MySqli Coding. 4) Before that, we have to create database and tables in our database with whom our frontend will form a uniform connection.



See below for full source code:- 

Now we describe our MySqli Coding step by step. Step 1 [$connect = mysqli_connect("localhost","root","","blog"); ] - We have created a connection between the page of the website with PhpMyadmin with the database "blog". Step 2 [$insert_query = "SELECT * from posts";] - WE are saying to select all the columns which are present in the table post. Step 3 [$run_query = mysqli_query($connect, $insert_query);] - we now running our query and saving it as $run_query. Step 4 [while($extract = mysqli_fetch_array($run_query)){] - we are running a while loop here so that the query can run till the selection of columns ends in the table posts. Step 5 [ $title = $extract["post_title"];] - we created a variable $title and save the value of post_title in it similarly we do the Step 6 and finally we print the output.

<?php
$connect = mysqli_connect("localhost","root","","blog");

$insert_query = "SELECT * from posts";
$run_query = mysqli_query($connect, $insert_query);
while($extract = mysqli_fetch_array($run_query)){
$title = $extract["post_title"];
$description  = $extract["post_desc"];
echo "<h1>$title</h1>";
}
?>

So after the creation of a connection between frontend and PHP MyAdmin, we are going to form a relation between the tables in a database "blog" named as "posts". We started extracting information from our database. We can do this both in Offline and Online Mode. In Offline Mode we have to download wamp server in our PC and after that, we have to save our website folder in www directory inside the www folder. we may run the source code by this way in an address bar of any browser LOCALHOST/name of the folder saved inside the www folder/. we can save our main page as index.php or index.html. we will work on MYSQLI (Latest version of Mysql). In Online mode, we should upload our main folder to the online server say Godaddy or Bigrock through FTP Software. On this case we will make some changes in our database connection such as  [$connect = mysqli_connect("localhost","username","password","blog"); ] username and password will be replaced with the respective username given by GoDaddy or whatever we have selected during setting of web server. DNS of the selected domain should be pointed to our web server to make our site live on the internet and we are ready to browse our website.

Video Tutorials:- 

We will go through video tutorials for the session (How to establish database connection using PHP and MySqli)




How to create a simple calculator using PHP

How to create a simple calculator using PHP 


So we will learn on this session, how to create a simple calculator on PHP 

<?php
  if(isset($_POST['submit'])){
 $num1 = $_POST['number1'];
 $num2 = $_POST['number2'];
 
 $result = $num1 + $num2;
 
 echo "<center><h2>$num1 + $num2 = $result</h2></center>";
  }



?>
<form method="post" action="calcu.php" enctype="multipart/form-data">
   Enter Numer One : <input type="text" name="number1"/><br>
   Enter Numer two : <input type="text" name="number2"/><br>
   <input type="submit" name="submit"/>
</form>

Now we will learn the above code with video tutorial :- 




How to echo hello world in php

How to echo "Hello World" in Php :-

What is PHP ?
PHP is a server side and secure language which is used to make dynamic and secure webpages



<?php
echo "<center><h1>Hello world</h1></center>"; 
?>

How can we write PHP Code?
Generally PHP code does not run in a browser. So we have to install wamp or xamp server in our system.

Some of the website made on PHP are -
1. Facebook.com (Social Networking Website)
2. Examdoor.in (Jobs Site)

How to install Wamp server?
http://www.wampserver.com/en/

We will use Notepad ++ and Google Chrome Browser



<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>

Learn How to Set Wamp Server in Windows PC -





How to echo hello world in php

How to echo "Hello World" in Php :-

What is PHP ?
PHP is a very interesting language. a web page created on normal HTML language can be seen on right click on it. But PHP is a secure language which is not viewable normally. So we can say that using PHP in our site is very useful as hackers have to think about it's not easy to hack. We can add more security as we wish in our admin panel. we can encrypt our password. Now many open source software is available in our market like Wordpress, Joomla etc for creating dynamic websites. But if we aware of PHP language with MYSQL (Database Knowledge) we can easily create our own CMS (Content Management System). We can modify it according to our wish. Some of the site such as facebook, Examdoor has their own CMS to modify according to their own wish



<?php
echo "<center><h1>Hello world</h1></center>"; 
?>

How can we write PHP Code?
Generally PHP code does not run in a browser. So we have to install wamp or xamp server in our system.

Some of the website made on PHP are -
1. Facebook.com (Social Networking Website)
2. Examdoor.in (Jobs Site)

How to install Wamp server?
http://www.wampserver.com/en/

We will use Notepad ++ and Google Chrome Browser

<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>

Learn How to Set Wamp Server in Windows PC -





Create a navigation menu using Html and Css

How to create a navigation menu using HTML and CSS

Navigation menu is very important for a website or a webpage. It gives a structural direction to all the topics of the website. And it is very important to design the menu in a beautiful manner. We will learn to create the navigation menu using HTML and CSS. we will provide Source Code and Video tutorials. 

Lets have a look of the menu here 

Now we will describe our Soure Code here!

<!DOCTYPE html>
<html>
 <head>
  <title>
   Navigation bar
  </title>
  <style>
    body{
margin:0;
padding:0;
}
    header{
height:40px;
width:100%;
background-color:black;
border-bottom:1px solid orange;
box-shadow:2px 3px 3px grey;
}
#navbar{
 width:600px;
 margin:0 auto;
 height:70%;
 
}
.box{
  width:18%;
  float:left;
  height:100%;
  margin-left:1%;
  padding-top:1%;
  padding-bottom:1%;
  text-align:center;
  color:white;
  font-family:Tahoma;
  
}
.box:hover{
 background-color:grey;
 border-radius:5px;
 cursor:pointer;
 color:#fff;
 font-weight:bolder;
 box-shadow:1px 2px 2px black;
}
  </style>
 </head>
<body>
 <header>
   <div id="navbar">
     <div class="box">Home</div>
<div class="box">Bollywood</div>
<div class="box">Hollywood</div>
<div class="box">Assam</div>
<div class="box">Bengal</div>
   </div>
 </header>
</body>
</html>

Video Tutorial for this code Comming Soon..

Advertisement

Translate