Class WPDA_Export_Sql

Exports tables or rows (depending on arguments)

  • Table export
    • One or more tables (batch)
    • Contains a create table statements for every tables exported
    • All records of a tables are exported as one insert statement
    • Contains comments (no reimport without editing possible)
  • Row export
    • All records are exported as one insert statement
    • Contains no comments (can be reimported without editing)
author Peter Schulz
since 1.0.0
package WPDataAccess\Utilities

 Methods

WPDA_Export constructor.

__construct() 

Make sure the export procedure has sufficient memory.

since 2.0.11

Main method to start export

export() 

This method checks arguments and starts the export according to the arguments provided.

since 1.0.0

Use this method to startan export using method arguments

export_with_arguments(string $mysql_set, string $show_comments, string $show_create, string $schema_name, string|array $table_names, string $export_type, string $include_table_settings = 'on'
since 2.0.7

Parameters

$mysql_set

string

on|off

$show_comments

string

on|off

$show_create

string

on|off

$schema_name

string

Database schema name

$table_names

stringarray

Single table name (string) | Table name list (array)

$export_type

string

table|row

$include_table_settings

string

on|off

Write insert into statement

insert_rows(string $table_name, string $where = '', boolean $show_comments = true
since 1.0.0

Parameters

$table_name

string

Database table name.

$where

string

Where clause.

$show_comments

boolean

Argument is needed for direct call from WPDA_Repository! (do not remove).

Define output stream

set_output_stream(\http\Encoding\Stream $output_stream) 

Used to stream an export to a file. Streaming helps to support exports of large files.

since 2.0.13

Parameters

$output_stream

\http\Encoding\Stream

Handle to output stream

Save column data types

column_data_types(array $table_columns) : array

This method creates a named array for all column names of a table in form: 'column_name' => 'data_type'

Argument $table_columns can be retrieved from WPDA_List_Columns->set_table_columns(). It must be prepared however with the idea that the instance of WPDA_List_Columns can be reused for best performance.

In fact this is just an array conversion.

since 1.0.0

Parameters

$table_columns

array

Column_names and data_types of a table (table name not used here).

Returns

arrayNamed array 'column_name' => 'data_type' for all columns in the table.

Write create table statement

create_table(string $table_name) : boolean
since 1.0.0

Parameters

$table_name

string

Database table name.

Returns

booleanIndicates whether table exists for further processing.

Set MySQL environment

db_begin() 
since 1.0.0

Set back MySQL environment

db_end() 
since 1.0.0

A row export was requested

export_rows() 
since 1.0.0

Export table settings

export_table_settings($table_name, boolean $show_comments = true
since 2.6.1

Parameters

$table_name

Table for which settings will be exported

$show_comments

boolean

Argument is needed for direct call from WPDA_Repository! (do not remove).

A table export was requested

export_tables() 
since 1.0.0

Set export header (filename)

header(string $file_name) 
since 1.0.0

Parameters

$file_name

string

Export filename.

Check if data type is numeric

is_numeric(string $data_type) : boolean
since 1.0.0

Parameters

$data_type

string

Data type (simple).

Returns

boolean

Depending on the type of export (streaming or echoing) the output is written to the export file.

write_output() 
since 2.0.13

Processing on invalid arguments

wrong_arguments() 
since 1.0.0

 Properties

 

Indicates whether table settings should be exported

$include_table_settings : string

Default

 

Indicates whether to set MySQL environment

$mysql_set : string

Default

 

Write output to stream if available

$output_stream : null

Default

null
 

Use variable to write output

$output_string : string

Default

 

Database schema name

$schema_name : string

Default

''
 

Database schema name prefix used in strings

$schema_name_prefix : string

Default

''
 

Indicates whether comments should be added

$show_comments : string

Default

 

Indicates whether to add a create table

$show_create : string

Default

 

Table name(s) of table(s) to be exported

$table_list : string | array

Default

array()