1

2つの質問があります

update_defile($array_value){...}1.)関数の書き方

define_file.php

<?php
  define("FIST_NAME", "something1");
  define("LAST_NAME", "something2");
  define("ADDRESS", "something3");
?>

「何か」は、メソッドごとに変更できる定数値ではありませんCall(update_defile($array_value)

値セット

$array_value = ("FIST_NAMe" => "duleep", "LAST_NAME" => "dissnayaka", "AGE" => "28" );

method(update_defile($array_value){.....}) を呼び出した後、「define_file.php」ファイルは次のようになりたい

<?php
  define("FIST_NAME", "duleep");
  define("LAST_NAME", "dissnayaka");
  define("ADDRESS", "something3");
  define("AGE", "28");
?>

2)。

私のデータベースは Oracle です。すでに構成値をデータベースに保存していますが、これらの構成値をアプリケーションで頻繁に使用しています。したがって、データベースから値を取得し、define_file.phpに保存してパフォーマンスを向上させます(データベースコールのダウンレート)が、パフォーマンスを向上させることができるかどうかはわかりませんPHPファイルの構成値を維持してください説明してください。アプリケーションのパフォーマンスを向上させる最善の方法と、他の代替ソリューションを歓迎します。

4

3 に答える 3

1
     public function update($form_config_arr)
   {

      if( (is_readable($config_file_path)) && is_writable($config_file_path))
      {
         if(!$config_old_file_content = file_get_contents($config_file_path))
         {
            throw new Exception('Unable to open file!');
         }

         $i = 0;
         $config_old_arr = array();
         $config_new_arr = array();

         foreach ($form_config_arr as $constant => $value){
            $config_old_line = $this->getLine($constant);
            $config_old_arr[$i] = $config_old_line;

            if(($value == 'true') || ($value == 'false')){
               $config_new_arr[$i] = "define ( '$constant', $value );\n";
            }else{
               $config_new_arr[$i] = "define ( '$constant', '$value' );\n";
            }
            $i++;
         }

         $config_new_file_content = str_replace($config_old_arr, $config_new_arr, $config_old_file_content);
         $new_content_file_write = file_put_contents($config_file_path, $config_new_file_content);

         foreach ($config_new_arr as $constant => $value)
         {
            echo $value.'<br/>';
         }
         return true;
      }else{
         throw new Exception('Access denied for '.$config_file_path);
         return false;
      }

   }

   /**
    *
    * @param string $constant
    * @return string
    */
   private function getLine($constant)
   {
      $match_line = '';
      $config_file = fopen($config_file_path, "r");
      if($config_file)
      {
         //Output a line of the file until the end is reached
         $i = 0;
         while(!feof($config_file))
         {
            $i++;
            $config_old_line = fgets($config_file);
            $pos = strpos($config_old_line, $constant);
            if( $pos !== false )
            {
               $match_line= $config_old_line;
            }
         }
         fclose($config_file);
         return $match_line;
      }else{
         throw new Exception('Unable to open file!');
      }

   }
于 2012-10-25T06:56:51.490 に答える
1

セッションを使用してそのような値を保存できないのはなぜですか。スクリプトのどこからでもアクセスして変更できます。

<?php
    session_start();
     $_SESSION["FIST_NAME"]= "something1";
    $_SESSION["LAST_NAME"]= "something2";
    $_SESSION["ADDRESS"]= "something3";


?>
于 2012-10-19T05:38:12.490 に答える
0

あなたがやろうとしているのは、ファイルを編集することです。別の php スクリプトを作成するだけです: updater.php データベースをポーリングし、値をフェッチして、define_file.php の値を更新します。

ここで PHP ファイル処理関数を探します: http://www.w3schools.com/php/php_file.asp

于 2012-10-19T05:36:16.127 に答える