Login   Register  
PHP Classes
elePHPant
Icontem

File: src/SQLTools/Command/AddForeignKey.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Rafael Lúcio  >  SQLTools  >  src/SQLTools/Command/AddForeignKey.php  >  Download  
File: src/SQLTools/Command/AddForeignKey.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: SQLTools
Create and alter databases, tables and indexes
Author: By
Last change:
Date: 1 year ago
Size: 790 bytes
 

Contents

Class file image Download
<?php

namespace SQLTools\Command;


class 
AddForeignKey extends AlterTable {

    private 
$localField;
    private 
$foreignTable;
    private 
$foreignField;
    private 
$fkName;

    public function 
__construct($table$localField$foreignTable$foreignField$fkName "")
    {
        
$this->table $table;
        
$this->localField $localField;
        
$this->foreignTable $foreignTable;
        
$this->foreignField $foreignField;
        
$this->fkName = ($fkName != "") ? $fkName "fk_" $foreignTable "_" $foreignField '_idx';
    }

    protected function 
getWhatToAdd()
    {
        return 
"CONSTRAINT " $this->fkName "
                FOREIGN KEY (
{$this->localField})
                REFERENCES " 
$this->foreignTable "({$this->foreignField})";
    }