How get all values in a column using PHP?

前端 未结 6 1291
悲&欢浪女
悲&欢浪女 2020-11-28 09:10

I\'ve been searching for this everywhere, but still can\'t find a solution: How do I get all the values from a mySQL column and store them in an array?

For eg: Tab

6条回答
  •  青春惊慌失措
    2020-11-28 10:04

    How to put MySQL functions back into PHP 7
    Step 1

    First get the mysql extension source which was removed in March:

    https://github.com/php/php-src/tree/PRE_PHP7_EREG_MYSQL_REMOVALS/ext/mysql

    Step 2

    Then edit your php.ini

    Somewhere either in the “Extensions” section or “MySQL” section, simply add this line:

    extension = /usr/local/lib/php/extensions/no-debug-non-zts-20141001/mysql.so
    

    Step 3

    Restart PHP and mysql_* functions should now be working again.

    Step 4

    Turn off all deprecated warnings including them from mysql_*:

    error_reporting(E_ALL ^ E_DEPRECATED);
    

    Now Below Code Help You :

    $result = mysql_query("SELECT names FROM Customers");
    $Data= Array();
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    {
            $Data[] =  $row['names'];  
    }
    

    You can also get all values in column using mysql_fetch_assoc

    $result = mysql_query("SELECT names FROM Customers");
        $Data= Array();
        while ($row = mysql_fetch_assoc($result)) 
        {
                $Data[] =  $row['names'];  
        }
    

    This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

    Reference


    YOU CAN USE MYSQLI ALTERNATIVE OF MYSQL EASY WAY


    *

     
    

提交回复
热议问题