Thursday, May 13, 2021
Home Databases Getting Data from MySql table in php

Getting Data from MySql table in php

mysqlFetching data from MySql server is a major factor in any kind of dynamic websites development. MySql makes it very easy.For fetching data from MySql server we must have to be in contact with a server connected.lets look at the following PHP script:

    function get_data(){
            $num = mysql_connect("localhost");
            $c = mysql_select_db("test");
    $sql = "SELECT * FROM checking WHERE shp_city = '3'";
            //echo $c;
    $int = mysql_query($sql,$num);
    $data = mysql_fetch_array($int,MYSQL_ASSOC);
    echo "<br />
    echo "data successfully got";

For fetching data from MySql first of all we got connected to our server using “mysql_connect” function and store the returned id into a variable. Now for fetching data from a specified database we have to connect to that database usnig “mysql_select_db” function passing the database name from which we are fetching data, as argument.then we wrote our sql query and stored it in another variable and now fetching data by using “mysql_query” function which takes a query and the id returned by “mysql_connect” as an argument. then we used mysql fetch array to get that data in the form of an array and printed in by using “print_r” function.So fetching data from Mysql is not that difficult.

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....