I develop my site with PHP, MySQL and I want to list a column name of my table translate.
I have written this code and it ain't working.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = translate;
This code works in MySQL but returns the name of the column in double, And it doesn't work in PHP.
This is my php code:
try{
$bdd -> new PDO('mysql:host=localhost;dbname=database;charset=utf8', 'root', '');
}catch (Exception $e)
{
die('Erreur: ' . $e->getMessage());
}
$req -> $bdd -> prepare('SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = translate;');
$req->execute();
Try This:-
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$dbname = 'dbname';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (!$conn) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully<br>';
$sql = 'SHOW COLUMNS FROM tablename';
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo $row["Field"] . "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
My Table is:-
Output is:-