2012年8月3日金曜日

ポストグレ PostGres ダンプ色々


//***********インサート形式でデータを抽出***********//
pg_dump -d DB名 -t テーブル名

//***********DBをバックアップ***********//
pg_dump DB名 > ファイル名.out

2012年7月13日金曜日

IEでJPGをアップロードするときの注意


 jpgの場合は、IEでは$_FILES['upload_image']['type'] == 'image/pjpeg'となるので注意

<!---------------------phpソース--------------------->
<?php
    session_cache_limiter('none');
    session_start();
   
    require_once('./helper/method.php');

    if($_FILES['upload_image']['name']){
        $msg = "OK";
        $upload_dir = '../file/plan/pc/';
        $upload_dir_sp = '../file/plan/sp/';
        $filename = $_FILES['upload_image']['name'];
        $uptime = date("YmdH_i_s");
        $name = $_FILES['upload_image']['tmp_name'];
       
        $flag= "";
        //画像アップ処理
        if($_FILES['upload_image']['type'] == 'image/jpeg' || $_FILES['upload_image']['type'] == 'image/pjpeg'){
            $testmsg = '.jpg';
            $upname =  $upload_dir.$uptime.'.jpg';
            $upname_sp = $upload_dir_sp.$uptime.'.jpg';
            $judg = move_uploaded_file($_FILES['upload_image']['tmp_name'],$upname);
            m_cpy_img($upname,$upname_sp);
        }else
        if($_FILES['upload_image']['type'] == 'image/gif'){
            $upname = $upload_dir.$uptime.'.gif';
            $upname_sp = $upload_dir_sp.$uptime.'.gif';
            $judg = move_uploaded_file($_FILES['upload_image']['tmp_name'],$upname);
            m_cpy_img($upname,$upname_sp);
        }else
        if($_FILES['upload_image']['type'] == 'image/ping'){
            $upname = $upload_dir.$uptime.'.png';
            $upname_sp = $upload_dir_sp.$uptime.'.png';
            $judg = move_uploaded_file($_FILES['upload_image']['tmp_name'],$upname);
            m_cpy_img($upname,$upname_sp);
        }else{
            $judg = false;
        }
        if($judg){
            $msg = "OK";
            smart_resize_image($upname,600,600,true);
            smart_resize_image($upname_sp,300,200,true);
            $dir = '/file/plan/pc/';
            $_SESSION['input_data']['pl_img1'] = $dir.basename($upname);
        }
    }else{
        $msg = "画像が選択されていません";
    }
    //************************************************
    // ファイルコピー
    //************************************************

        function m_cpy_img($file_img_in,$file_img_out){
            if ( file_exists( $file_img_in )) {
                copy( $file_img_in, $file_img_out );
            }
        }
   
?>
<script type="text/javascript">
<!--
    var flag = '<?php echo $msg; ?>';
   
    if(flag == "OK"){
        var container = parent.document.getElementById('container1');
       
        image = parent.document.createElement('img');
       
        image.src = '<?php if($upname){ print($upname); }else{ print("../file/photo/no-img.jpg"); }?>';

        parent.document.planform.pl_img1.value='<?php if($upname){ print($upname); }?>';

        container.innerHTML = '';
        container.appendChild(image);
    }else{
        alert(flag);
    }
//-->
</script>
</body>
</html>
<!-----------------HTML----------------------->
                        <tr>
                            <th>
                                プラン 料理画像※
                            </th>
                            <td>
                                <iframe name="uploader1" src="" style="width:0px;height:0px;border:0px;"></iframe>
                                <form action="uploader1.php" method="post" enctype="multipart/form-data" target="uploader1">
                                    <input type="hidden" name="max_file_size" value="1000000" />
                                    <input type="file" name="upload_image" />
                                    <input type="submit" value="料理画像アップロード"/>
                                </form>
                                <!--------画像表示先---------->
                                <div id="container1">
                                    {if $dataList.pl_img1}<img src="{$dataList.pl_img1}" id="pl_img1">{/if}
                                </div>
                            </td>
                        </tr>

2012年7月11日水曜日

MYSQLで配列を格納検索を行うテスト

/*MYSQLで配列*/
/*********テーブルの作成************/
create table tbl1
(id       int  AUTO_INCREMENT ,
 name     varchar(10),
 lng      SET('1','2','3','4','5','6'),
 PRIMARY KEY ( `id` )
)

/****************データの挿入******************/

INSERT INTO tbl1 (name,lng) values ('a','1,2');
INSERT INTO tbl1 (name,lng) values ('b','2');
INSERT INTO tbl1 (name,lng) values ('c','2,3');
INSERT INTO tbl1 (name,lng) values ('d','2,4');


/*************************検索**************************/

/*検索 完全一致*/
SELECT * FROM tbl1 WHERE lng LIKE '%1,4%';
/*検索 配列の値複数詮索*/
SELECT * FROM tbl1 WHERE lng = '1,2';

/*配列に値があれば*/
SELECT * FROM tbl1 WHERE lng & '1';

2012年6月9日土曜日

phpのセッションについて詳しく書いてあったんで

http://pentan.info/php/session_gc.html

サクラエディタのPHP強調キーワード設定方法

開発ではサクラエディタを使っているんですが 設定の方法が乗っているサイトです。 http://memorva.jp/memo/windows/sakura_php_kwd_khp.php

2012年6月5日火曜日

PHP ファイルダウンロード


<?php
// ダウンロードさせるファイル名
$tmp_file = "test.txt";
$j_file   = "テスト.txt";
$j_file   = mb_convert_encoding($j_file, "SJIS", "EUC");
// ヘッダ
header("Content-Type: application/octet-stream");
// ダイアログボックスに表示するファイル名
header("Content-Disposition: attachment; filename=$j_file");
// 対象ファイルを出力する。
readfile($tmp_file);
exit;
?>


2012年4月15日日曜日

ヒントsql

//a1_idが2でa1_formの配列1次元配列の最大要素数の値とa2_idが同じものを抽出
SELECT * FROM a1,a2
where a1.a1_id = 2
AND cast(array_upper(a1.a1_form,1)as integer) = a2.a2_id

2012年4月2日月曜日

MYSQL クエリ文字コード指定

#下記のコマンドを実行し、文字コードを指定
SET CHARACTER SET utf8

MYSQL ダンプ作成

#下記のコマンドを実行し、ダンプを作成
$ mysqldump -h 「サーバ名」 -u 「ユーザ名」 -p 「パスワード」 > dump_20120314.sql

2012年3月16日金曜日

DBからのタイムスタンを年月日

date('Y.m.d',strtotime($accessData[$key]['jsk_update_date']));


2012年3月15日木曜日

.htaccessでPCと携帯とスマフォ判定

<IfModule mod_rewrite.c>
RewriteEngine On

#######スマフォサイト########
# iPod
RewriteCond %{HTTP_USER_AGENT} (iPod|iPhone|DDIPOKET|iPad|J-Android|Vodafone|SoftBank)
RewriteRule ^$ /morimoto/test/sp/ [R]


#######携帯サイト########
RewriteCond %{HTTP_USER_AGENT} (DoCoMo|KDDI|DDIPOKET|UP\.Browser|J-PHONE|Vodafone|SoftBank)
RewriteRule ^$ /morimoto/test/mb/ [R]

#######PCサイト########
RewriteRule ^$ /morimoto/test/pc/ [R]
</IfModule>

2012年2月20日月曜日

php ture false nullて

$hantei_txt = array(
array("","ダブルクオート空文字")
,array('',"シングルオート空文字")
,array(0,"数値ゼロ")
,array(1,"数値1")
,array(01,"数値01")
,array("0","文字列ゼロ")
,array("1","文字列イチ")
,array(TURE,"ture")
,array(FALSE,"false")
,array("TURE","文字列 ture")
,array("FALSE","文字列 false")
,array(null," NULL")
,array("null","文字列NULL")
);
$count_num = count($hantei_txt);
for($i = 0; $i < $count_num; $i++){ if($hantei_txt[$i][0]){ echo $hantei_txt[$i][1]."="; echo "hit"; }else{ echo $hantei_txt[$i][1]."="; echo "none"; } echo "
";
}

ダブルクオート空文字=none
シングルオート空文字=none
数値ゼロ=none
数値1=hit
数値01=hit
文字列ゼロ=none
文字列イチ=hit
ture=hit
false=none
文字列 ture=hit
文字列 false=hit
NULL=none
文字列NULL=hit

2012年2月19日日曜日

sql nullでないものを返す

使い方は引数の中でNULLでないもの返すので、たとえばこんな感じ
//セレクトとき
select COALESCE(カラム1, カラム2,カラム3) from user_master

//インサートとき
INSERT INTO
`tr_a`
(`a_id`,
`a_num`)
VALUES
(null,
COALESCE(null,0)
)

2012年2月12日日曜日

Macで新規ファイル作成コマンド

MACでは
$ touch ファイル名
コマンドでファイルを作成します。

2012年1月16日月曜日

smartyで文字列加工

修飾子

変数が空の場合のデフォルト値

{"test1"|default:"????"}

{""|default:"????"}


エスケープ

{""}

{"''"|escape}

htmlタグの削除

{"test"|strip_tags}

時間

{$smarty.now}
{$smarty.now+60*60*24|date_format:"%w"}

{$smarty.now|date_format:"%Y年%m月%d日%h時%M分%S秒"}

改行文字を変換
{$data|nl2br}
スペース
を変換


{$data|strip:""}

テンプレート内で変数を生成

{assign var="num" value="99999"}
テンプレート内の値は{$num}

smarty オブジェクトで操作

require_once('MySmarty.php');
require_once('user_bean.php');

$uses=array();
$uses[] = new user_bean(1,"test_1","2011/01/01");
$uses[] = new user_bean(2,"test_2","2010/01/01");
$uses[] = new user_bean(3,"test_3","2009/01/01");
           
$mysmarty = new MySmarty();
$mysmarty->assign('msg','hello MySmarty');
$mysmarty->assign('uses',$uses);
$mysmarty->display('index.tpl');
?>
//beanクラス
<?php
class user_bean{
    //プロパティ
    public $name;
    public $id;
    public $birth;
    //メソッド
    function __construct($id,$name,$birth){
        $this->id = $id;
        $this->name = $name;
        $this->birth = $birth;
    }
    public function getage(){
        return floor((time()-strtotime($this->birth))/(60*60*24*365));
    }
}
?>

//テンプレート
{foreach from=$uses item=use}
    <p>id {$use->id}</p>
    <p>名前 {$use->name}</p>
    <p>歳 {$use->getage()}</p>
{/foreach}

Smarty 連想配列

//プログラム
<?php
require_once('MySmarty.php');
require_once('DB.php');


$dbh = DB::connect('mysql://root:mysql@127.0.0.1/test');

$data = array(    "id"    =>    1,
                "shimei"=>array("ue"=>"yamada",
                                "shita"=>"taro")
              );               
$mysmarty = new MySmarty();
$mysmarty->assign('msg','hello MySmarty');
$mysmarty->assign('data',$data);
$mysmarty->display('index.tpl');
?>
//テンプレート
<h1>{$msg}</h1>
{$data.id}<br />
{$data.shimei.ue}<br />
{$data.shimei.shita}<br />

//表示

hello MySmarty

1
yamada
taro

Smarty DBからレコードを取り出し、テンプレート表示 テスト

mysql> insert into test_1(id,name) values(1,'test'),(2,'test2');
Query OK, 1 row affected (0.05 sec)

//レコードの確認
mysql> select * from test_1;
+------+-------+
| id   | name  |
+------+-------+
|    1 | test  |
|    2 | test2 |


//プログラム
<?php
$dbh = DB::connect('mysql://root:mysql@127.0.0.1/test');

//sql文の作成
$sql = $dbh->prepare("SELECT * FROM test_1");
$data = array();
$rs = $dbh->execute($sql);
//配列へ挿入
while($row = $rs->fetchRow(DB_FETCHMODE_ASSOC)){
    $data[]=array("id" => $row['id'],"name"    => $row['name']);
}

$mysmarty = new MySmarty();
$mysmarty->assign('msg','hello MySmarty');
$mysmarty->assign('data',$data);
$mysmarty->display('index.tpl');
?>
//テンプレート部分

<h1>{$msg}</h1>
{foreach from=$data item=datum}
    <p>{$datum.id}</p>
    <p>{$datum.name}</p>
{/foreach}



smarty 入門

/*************************************************/
/*        仕事でSmartyを使うんでおさらい     */
/************************************************/


/*-----------ダウンロード---------*/
「http://www.smarty.net/download」より「Smarty 2.6.26」をダウンロード

/*-----------インストール----------*/
「Smarty 2.6.26」を展開し「Smarty」とリネイムし、
今回は「Windows」+「Ampps」環境なので「C:\Ampps\Smarty」に配置する。

/*------------php.iniの設定----------*/
//下記を編集
include_path = ".;C:\ampps\php\includes;C:\Ampps\Smarty\lib"

/*------------ディレクトリの配置----------------------*/
/*下記のように配置します。*/
smarty_sample-
              |-test_app_1
                    |-templates     //テンプレートファイル設置
                    |-templates_c   //コンパイルしたテンプレート設置
                    |-configs       //コンフィグファイル設置
                    |-cache         //キャッシュ
                   
                   
                   
                   
/*--------------テンプレートの作成---------------------------------*/
下記のhtmlソースを「templates_c\index.tpl」に配置、

{*----   テストテンプレート   ----*}

<html>
<head>
<title>Test_1</title>
</head>
<body>

<h1>{$msg}</h1>

</body>
</html>

/*--------------プログラムの作成---------------------------------*/

/*下記を「C:\Ampps\www\smarty_sample\test_app_1」に配置*/
<?php

{*require_once('C:/Ampps/Smarty/libs/Smarty.class.php');*}
require_once('marty.class.php');

$smarty = new Smarty();

$smarty->template_dir = 'C:\Ampps\smarty_sample\test_app_1/templates/';
$smarty->compile_dir  = 'C:\Ampps\smarty_sample\test_app_1/templates_c/';
$smarty->config_dir   = 'C:\Ampps\smarty_sample\test_app_1/configs/';
$smarty->cache_dir    = 'C:\Ampps\smarty_sample\test_app_1/cache/';

$smarty->assign('msg','Hello World!');
$smarty->display('index.tpl');

?>

2012年1月11日水曜日

phpとmysqlでテーブルの存在確認

<?php
    $host = "localhost";
    $user   = "root";
    $pass = "mysql";
    $db = "test";
 $con = mysql_connect($host,$user,$pass) or die("db接続NG");
 print "db接続OK";
//テーブルチェック関数の呼出
    if(table_exists($db,'item',$con)){
     print "item table hit";
    }else{
     print "item table none";
    }
 mysql_close();


// テーブルの存在チェック関数の定義  start
 function table_exists($db_name,$tbl_name,$db)
 {
  // テーブルリストの取得
  $rs = mysql_query("SHOW TABLES FROM $db_name");
  while($arr_row = mysql_fetch_row($rs)){
    if(in_array($tbl_name,$arr_row)){
      return true;
    }
  }
  return false;
 }
// テーブルの存在チェック関数の定義  end
?>