\SyncDb_MySQL

This class will update a database to match a given db structure schema (described below)

-- db structure layout guide --

array(
    "<table name>"=>array(
        "<column name>"=>array(
            "Field"=>"<column name>",
            "Type"=>"<column type>",
            "Null"=>"<YES|NO>",
            "Key"=>"<PRI|UNI|MUL|empty>", //note: PRI=Primary Key, UNI=Unique index, MUL=multiple... seems to mean the same as UNI though
            "Default"=>"<default value|empty>",
            "Extra"=>"<auto_increment|empty>",
            "Collation"=>"<utf8_general_ci|utf8mb4_unicode_ci|latin1_swedish_ci|empty>", //other collations can easily be added if needed
            "IndexType"=>"<UNIQUE|NONUNIQUE|FULLTEXT|empty>", //UNIQUE when Key=PRI,UNI, or MUL. MUL could also mean NONUNIQUE. FULLTEXT for fulltext index
        ),
        ...(more columns)...
    ),
    ...(more tables)...
)

--- EXAMPLE ---

function getDbStructure(){
    return array(
        "Template"=>array(
            "TemplateId"=>array(
                "Field"=>"TemplateId",
                "Type"=>"int(1) unsigned",
                "Null"=>"NO",
                "Key"=>"PRI",
                "Default"=>"",
                "Extra"=>"auto_increment",
            "Collation"=>"",
            "IndexType"=>"UNIQUE",
            ),
            "Name"=>array(
                "Field"=>"Name",
                "Type"=>"varchar(255)",
                "Null"=>"NO",
                "Key"=>"UNI",
                "Default"=>"",
                "Extra"=>"",
            "Collation"=>"",
            "IndexType=>"",
            ),
            "Html"=>array(
                "Field"=>"Html",
                "Type"=>"text",
                "Null"=>"YES",
                "Key"=>"",
                "Default"=>"",
                "Extra"=>"",
            "Collation"=>"utf8_general_ci",
            "IndexType"=>"FULLTEXT", //i.e. fulltext index on this column
            ),
            "__sqlCreateTable"=>"
                CREATE TABLE `Template` (
                      `TemplateId` int(1) UNSIGNED NOT NULL AUTO_INCREMENT
                    ,`Name` varchar(255) NOT NULL UNIQUE
                    ,`Html` text NULL
                    ,PRIMARY KEY (`TemplateId`)
                );
            "
        )
);

Summary

Methods
Properties
Constants
Instance()
DoSync()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
Initialize()
__construct()
BuildResults()
InsertNewFields()
CheckForFieldUpdates()
BackupTable()
AddPrimaryKey()
AddIndex()
AddFulltextIndex()
DropPrimaryKey()
DropIndex()
DropFulltextIndex()
CreateTable()
InsertField()
DeleteField()
UpdateField()
IsValidCollation()
GetCollationSql()
BackupTableIfNeeded()
Query()
Message()
$_dbManager
$_tablesBackedUp
$_tablesCreated
$_keysToAdd
$_indexesToAdd
$_fulltextToAdd
$_keysToDrop
$_indexesToDrop
$_fieldsToUpdate
$_lastSyncResults
$_lastSyncResultsMessage
$_backupTables
$_doInsert
$_doUpdate
$_doDelete
$_debugMode
$instance
N/A

Properties

$_dbManager

$_dbManager : 

Type

$_tablesBackedUp

$_tablesBackedUp : 

Type

$_tablesCreated

$_tablesCreated : 

Type

$_keysToAdd

$_keysToAdd : 

Type

$_indexesToAdd

$_indexesToAdd : 

Type

$_fulltextToAdd

$_fulltextToAdd : 

Type

$_keysToDrop

$_keysToDrop : 

Type

$_indexesToDrop

$_indexesToDrop : 

Type

$_fieldsToUpdate

$_fieldsToUpdate : 

Type

$_lastSyncResults

$_lastSyncResults : 

Type

$_lastSyncResultsMessage

$_lastSyncResultsMessage : 

Type

$_backupTables

$_backupTables : 

Type

$_doInsert

$_doInsert : 

Type

$_doUpdate

$_doUpdate : 

Type

$_doDelete

$_doDelete : 

Type

$_debugMode

$_debugMode : 

Type

$instance

$instance : 

Type

Methods

Instance()

Instance() 

DoSync()

DoSync(  $dbManager,   $newDbStructure,   $backupTables = true,   $doInsert = true,   $doUpdate = true,   $doDelete = true,   $debugMode = false) 

Parameters

$dbManager
$newDbStructure
$backupTables
$doInsert
$doUpdate
$doDelete
$debugMode

Initialize()

Initialize() 

__construct()

__construct() 

BuildResults()

BuildResults() 

InsertNewFields()

InsertNewFields(  $newDbStructure,   $tableName) 

Parameters

$newDbStructure
$tableName

CheckForFieldUpdates()

CheckForFieldUpdates(  $tableName,   $currentField,   $newField) 

Parameters

$tableName
$currentField
$newField

BackupTable()

BackupTable(  $tableName) 

Parameters

$tableName

AddPrimaryKey()

AddPrimaryKey(  $tableName,   $fieldName) 

Parameters

$tableName
$fieldName

AddIndex()

AddIndex(  $tableName,   $fieldName,   $unique) 

Parameters

$tableName
$fieldName
$unique

AddFulltextIndex()

AddFulltextIndex(  $tableName,   $fieldName) 

Parameters

$tableName
$fieldName

DropPrimaryKey()

DropPrimaryKey(  $tableName) 

Parameters

$tableName

DropIndex()

DropIndex(  $tableName,   $fieldName) 

Parameters

$tableName
$fieldName

DropFulltextIndex()

DropFulltextIndex(  $tableName,   $fieldName) 

Parameters

$tableName
$fieldName

CreateTable()

CreateTable(  $tableName,   $fields) 

Parameters

$tableName
$fields

InsertField()

InsertField(  $tableName,   $newDbField) 

Parameters

$tableName
$newDbField

DeleteField()

DeleteField(  $tableName,   $fieldName) 

Parameters

$tableName
$fieldName

UpdateField()

UpdateField(  $tableName,   $newDbField,   $includeAutoIncrement = true) 

Parameters

$tableName
$newDbField
$includeAutoIncrement

IsValidCollation()

IsValidCollation(  $dataType) 

Parameters

$dataType

GetCollationSql()

GetCollationSql(  $dbField) 

Parameters

$dbField

BackupTableIfNeeded()

BackupTableIfNeeded(  $tableName) 

Parameters

$tableName

Query()

Query(  $sql) 

Parameters

$sql

Message()

Message(  $str = "") 

Parameters

$str