コード例 #1
0
ファイル: mysql.php プロジェクト: brynner/postr
 /**
  * Returns the alter query builder
  *
  * @return Eden_Sql_Alter
  */
 public function alter($name = NULL)
 {
     //Argument 1 must be a string or null
     Eden_Mysql_Error::i()->argument(1, 'string', 'null');
     return Eden_Mysql_Alter::i($name);
 }
コード例 #2
0
ファイル: eden.php プロジェクト: rafamaxber/Arkay-sync
if(!class_exists('Eden_Mysql')){class Eden_Mysql extends Eden_Sql_Database{protected $_host='localhost';protected $_name=NULL;protected $_user=NULL;protected $_pass=NULL;protected $_model=self::MODEL;protected $_collection=self::COLLECTION;public static function i(){return self::_getMultiple(__CLASS__);}public function __construct($host,$name,$user,$pass=NULL,$port=NULL){Eden_Mysql_Error::i()->argument(1,'string','null')->argument(2,'string')->argument(3,'string')->argument(4,'string','null')->argument(5,'numeric','null');$this->_host=$host;$this->_name=$name;$this->_user=$user;$this->_pass=$pass;$this->_port=$port;}public function alter($name=NULL){Eden_Mysql_Error::i()->argument(1,'string','null');return Eden_Mysql_Alter::i($name);}public function create($name=NULL){Eden_Mysql_Error::i()->argument(1,'string','null');return Eden_Mysql_Create::i($name);}public function connect(array $options=array()){$host=$port=NULL;if(!is_null($this->_host)){$host='host='.$this->_host.';';if(!is_null($this->_port)){$port='port='.$this->_port.';';}}$connection='mysql:'.$host.$port.'dbname='.$this->_name;$this->_connection=new PDO($connection,$this->_user,$this->_pass,$options);$this->trigger();return $this;}public function subselect($parentQuery,$select='*'){Eden_Mysql_Error::i()->argument(2,'string');return Eden_Mysql_Subselect::i($parentQuery,$select);}public function utility(){return Eden_Mysql_Utility::i();}public function getColumns($table,$filters=NULL){Eden_Mysql_Error::i()->argument(1,'string');$query=$this->utility();if(is_array($filters)){foreach($filters as $i=>$filter){$format=array_shift($filter);$filter=$this->bind($filter);$filters[$i]=vsprintf($format,$filter);}}$query->showColumns($table,$filters);return $this->query($query,$this->getBinds());}public function getPrimaryKey($table){Eden_Mysql_Error::i()->argument(1,'string');$query=$this->utility();$results=$this->getColumns($table,"`Key`='PRI'");return isset($results[0]['Field']) ? $results[0]['Field'] : NULL;}public function getSchema(){$backup=array();$tables=$this->getTables();foreach($tables as $table){$backup[]=$this->getBackup();}return implode("\n\n",$backup);}public function getTables($like=NULL){Eden_Mysql_Error::i()->argument(1,'string','null');$query=$this->utility();$like=$like ? $this->bind($like) : NULL;$results=$this->query($query->showTables($like),$q->getBinds());$newResults=array();foreach($results as $result){foreach($result as $key=>$value){$newResults[]=$value;break;}}return $newResults;}public function getTableSchema($table){Eden_Mysql_Error::i()->argument(1,'string');$backup=array();$schema=$this->getColumns($table);if(count($schema)){$query=$this->create()->setName($table);foreach($schema as $field){$fieldTypeArray=explode(' ',$field['Type']);$typeArray=explode('(',$fieldTypeArray[0]);$type=$typeArray[0];$length=str_replace(')','',$typeArray[1]);$attribute=isset($fieldTypeArray[1]) ? $fieldTypeArray[1] : NULL;$null=strtolower($field['Null'])=='no' ? false : true;$increment=strtolower($field['Extra'])=='auto_increment' ? true : false;$q->addField($field['Field'],array( 'type'=>$type,'length'=>$length,'attribute'=>$attribute,'null'=>$null,'default'=>$field['Default'],'auto_increment'=>$increment));switch($field['Key']){case 'PRI': $query->addPrimaryKey($field['Field']);break;case 'UNI': $query->addUniqueKey($field['Field'],array($field['Field']));break;case 'MUL': $query->addKey($field['Field'],array($field['Field']));break;}}$backup[]=$query;}$rows=$this->query($this->select->from($table)->getQuery());if(count($rows)){$query=$this->insert($table);foreach($rows as $index=>$row){foreach($row as $key=>$value){$query->set($key,$this->getBinds($value),$index);}}$backup[]=$query->getQuery(true);}return implode("\n\n",$backup);}}}