I'm coding in PHP. I have the following mySQL table:
CREATE TABLE `students` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`Name` varchar(255) DEFAULT NULL,
`Start` int(10) DEFAULT NULL,
`End` int(10) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB;
I'm trying to use the mysqli_query function in PHP to DESCRIBE the table.
Here's my code:
$link = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DATABASE);
$result = mysqli_query($link,"DESCRIBE students");
The documentation says For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object.
But from there I don't know how to print $result
so that it shows the query results. If possible I want to print $result so that it looks like:
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ID | int(10) | NO | PRI | NULL | auto_increment |
| Name | varchar(255) | YES | | NULL | |
| Start | int(10) | YES | | NULL | |
| End | int(10) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
My other question is how to print the query SHOW CREATE TABLE students
.
$result = mysqli_query($link,"SHOW CREATE TABLE students");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…