-2

Here is my function .Earlier it was working in a very better way but now a day it is not working well .

function table_rows()
    {

    $sql="SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='check_db' AND `TABLE_NAME`='tbl_details'";
    $result= mysql_query($sql);

    return $result;
    }

The function results..Something like this .I want only field names.

COLUMN_NAME
tbl_structure.php?change_column=1&field=id&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=fnme&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=lnme&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=age&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=dob&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=mail&token=8a5756ad27bfde74d341bfed684767e5
tbl_structure.php?change_column=1&field=ads&token=8a5756ad27bfde74d341bfed684767e5
  • no idea what you are asking –  Feb 28 '17 at 00:43
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Feb 28 '17 at 01:39

1 Answers1

-1

first, mysql_ is deprecated. Use mysqli_ or PDO

second, you are only executing the sql query, but not fetching any data. Try the code below. Note that $con is the variable to connect to db. You should change it to your own

(Edited) https://www.w3schools.com/php/func_mysqli_query.asp https://www.w3schools.com/php/func_mysqli_fetch_array.asp

function db () {
    static $con;
    if ($con===NULL){ 
        $con = mysqli_connect ("localhost", "root", "", "database");
    }
    return $con;
}

function table_rows()
  {
    $con = db();
    $sql="SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='check_db' AND `TABLE_NAME`='tbl_details'";

    $query= mysqli_query($con,$sql);
    $result= mysqli_fetch_array($query,MYSQLI_ASSOC);

    return $result;
 }
Nodir Rashidov
  • 692
  • 9
  • 32