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.

Latest Content