Answers for "php pdo get query column names"

PHP
1

php pdo get database name

$pdo->query('select database()')->fetchColumn();
Posted by: Guest on January-25-2021
0

Fetching Columns Using PDO (PHP DATA OBJECT)

Code:
$conn = new PDO("mysql:host=localhost;dbname=db_user", "root", "");
$query = $conn->prepare("SELECT * FROM tbl_user WHERE id > ?");
            $query->execute([10]);
            $result = $query->fetchAll(PDO::FETCH_COLUMN, 1);
            echo "<pre>";
            print_r($result);
            echo "</pre>";
            
Output:
Array
(
    [0] => Fatema Akter
    [1] => Roksana Akter
    [2] => Syed Fahim
    [3] => Tonmoy Ahmed 
    [4] => Jannatul Ferdous
    [5] => Mahabuba Rahman Porshi
    [6] => Kaium Ahmed
    [7] => Rabbi Islam
    [8] => Md. Fahad Monshi
    [9] => Arif Hossain
)
Posted by: Guest on July-08-2021

Browse Popular Code Answers by Language