abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

6/10/2018

selecting data from mysql data using php

hi,
how to connect php to mysql & select data from mysql

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

// Create connection $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, firstname, lastname FROM sample";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "no record found";
}

mysqli_close($conn);
?>



in the above shows that how pass connection in above example use mysqli_num_rows & mysqli_fetch_assoc to fetching result according yo number of rows & associated result.
in this use while loop to pass all associated columns. try above example comment if any

2 comments:

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...