GetColumnCount() public method

This function returns the number of columns or returns FALSE on error
public GetColumnCount ( string $table = "" ) : integer
$table string (Optional) If a table name is not specified, the column count is returned from the last query
return integer The total count of columns
Example #1
0
 function dumpTableData($table)
 {
     $conn = new MySQL(true, DBNAME, DBHOST, DBUSER, DBPASS, "", true);
     $strTables = "SELECT * FROM `{$table}`";
     $conn->QueryArray($strTables);
     $cntTables = $conn->RowCount();
     if ($cntTables) {
         $num_fields = $conn->GetColumnCount($table);
         $this->output .= "\n\n";
         $this->output .= "-- \n";
         $this->output .= "-- Dumping data for table `{$table}` \n";
         $this->output .= "-- \n\n";
         $fields = '';
         $field_type = array();
         $i = 0;
         while ($i < $num_fields) {
             if (!$fields) {
                 $fields = "`" . $conn->GetColumnName($i, $table) . "`";
             } else {
                 $fields .= ", " . "`" . $conn->GetColumnName($i, $table) . "`";
             }
             //                array_push($field_type, $conn->GetColumnDataType($i, $table));
             $i++;
         }
         $conn->MoveFirst();
         while (!$conn->EndOfSeek()) {
             $rsTable = $conn->RowArray();
             $this->output .= "INSERT INTO `{$table}` ({$fields}) VALUES (";
             for ($i = 0; $i < $num_fields; $i++) {
                 if (is_null($rsTable[$i])) {
                     $this->output .= "null";
                 } else {
                     switch ($field_type[$i]) {
                         case 'int':
                             $this->output .= $rsTable[$i];
                             break;
                         case 'string':
                         case 'blob':
                         default:
                             $this->output .= "'" . addslashes($rsTable[$i]) . "'";
                             break;
                     }
                 }
                 if ($i < $num_fields - 1) {
                     $this->output .= ", ";
                 }
             }
             $this->output .= ");\n";
         }
     }
     $this->output .= "\n";
 }