<?php
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class
include('../conn_mysql.php');
// creates object with connection to MySQL
$conn = new PDO_MySQLi($mysql);
// simple SHOW, without placeholders
$sql = "SHOW COLUMNS FROM `testclass`";
// executes the SQL query (passing only the SQL query), and gets the selected rows
$rows = $conn->sqlExecute($sql);
// gets the number of rows with returned data (number of columns in table)
$nr_c = $conn->num_rows;
// if there are returned columns, traverses the array with columns data, using foreach(), and outputs each column name and its type
if($nr_c > 0) {
echo 'Number of columns: '. $nr_c;
foreach($rows AS $row) {
echo '<br/>Column = "'. $row['Field'] .'" / Type = '. $row['Type'];
}
}
else {
if($conn->error) echo $conn->error; // if error, outputs it
echo '0 selected results';
}
|