PHP Classes

File: examples/10-show_columns.php

Recommend this page to a friend!
  Classes of MarPlo   PDO_MySQLi class   examples/10-show_columns.php   Download  
File: examples/10-show_columns.php
Role: Example script
Content type: text/plain
Description: Example 10
Class: PDO_MySQLi class
Access MySQL using PDO or MySQLi extensions
Author: By
Last change:
Date: 10 years ago
Size: 927 bytes


Class file image Download
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class

// 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) {
'Number of columns: '. $nr_c;

$rows AS $row) {
'<br/>Column = "'. $row['Field'] .'" / Type = '. $row['Type'];
else {
$conn->error) echo $conn->error; // if error, outputs it
echo '0 selected results';