当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::quoteSql方法代码示例

本文整理汇总了PHP中yii\db\Connection::quoteSql方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::quoteSql方法的具体用法?PHP Connection::quoteSql怎么用?PHP Connection::quoteSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\db\Connection的用法示例。


在下文中一共展示了Connection::quoteSql方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $command = $this->db->createCommand();
     $changed = false;
     foreach ($this->nameSpaces as $key => $nameSpace) {
         if (is_integer($key)) {
             $alias = '@' . str_replace('\\', '/', $nameSpace);
             $path = \Yii::getAlias($alias);
         } else {
             $path = $key;
         }
         if (!is_dir($path)) {
             echo 'Directory not exist' . PHP_EOL;
             echo 'Path - "' . $path . '"' . PHP_EOL;
             echo 'Namespace - "' . $nameSpace . '"' . PHP_EOL . PHP_EOL;
             break;
         }
         foreach (glob($path . '*.php') as $file) {
             $info = pathinfo($file);
             $modelCls = $nameSpace . $info['filename'];
             /**
              * @var $model ActiveRecord
              */
             $model = new $modelCls();
             if (!$model instanceof ActiveRecord) {
                 break;
             }
             if (!method_exists($model, 'attributeTypes')) {
                 echo 'Required method "' . get_class($model) . '::attributeTypes()" not found.';
                 break;
             }
             $tblName = $model->tableName();
             $fieldTypes = $model->attributeTypes();
             $schema = $this->db->getTableSchema($tblName, true);
             $fullTblName = $schema ? $schema->fullName : null;
             if (null !== $fullTblName && in_array($fullTblName, $this->tableNames)) {
                 $currColNames = $schema->getColumnNames();
                 $newColumns = array_diff(array_keys($fieldTypes), $currColNames);
                 $removeColumns = array_diff($currColNames, array_keys($fieldTypes));
                 if (!empty($newColumns)) {
                     echo 'Add new column(s) to the table "' . $fullTblName . '"' . PHP_EOL;
                     foreach ($newColumns as $colName) {
                         $command->addColumn($tblName, $colName, $fieldTypes[$colName]);
                         $command->execute();
                         echo '  Column "' . $colName . '" added with type [' . $fieldTypes[$colName] . ']' . PHP_EOL;
                     }
                     $changed = true;
                     echo 'Done.' . PHP_EOL . PHP_EOL;
                 }
                 if (!empty($removeColumns)) {
                     echo 'Remove column(s) from the table "' . $fullTblName . '"' . PHP_EOL;
                     foreach ($removeColumns as $colName) {
                         $command->dropColumn($tblName, $colName);
                         $command->execute();
                         echo '  Column "' . $colName . '" is removed' . PHP_EOL;
                     }
                     $changed = true;
                     echo 'Done.' . PHP_EOL . PHP_EOL;
                 }
             } else {
                 $command = $this->db->createCommand();
                 $command->createTable($tblName, $fieldTypes);
                 $command->execute();
                 $changed = true;
                 echo 'New table "' . trim($this->db->quoteSql($tblName), '`') . '" is created.' . PHP_EOL;
             }
         }
     }
     if (!$changed) {
         echo 'Changes not found.' . PHP_EOL;
     }
 }
开发者ID:goodizer,项目名称:yii2-helpers,代码行数:72,代码来源:DbSyncHelper.php


注:本文中的yii\db\Connection::quoteSql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。