[PHP] sprintf / PDO::bindParam() > Web

본문 바로가기

사이트 내 전체검색

Web

[PHP] sprintf / PDO::bindParam()

작성일 23-01-04 20:02

페이지 정보

작성자sbLAB 조회 3,621회 댓글 0건

본문

 sprintf 

%0.8s  <=== ?? 


    <?php
    $ext = 'png';
    $filename = 'filename';

    echo sprintf('%s_%s.%0.8s', date("YmdHis"), $filename, $ext);
    // 20230104105802_filename.png

    echo '<br>';

    echo sprintf('%s_%s.%0.2s', date("YmdHis"), $filename, $ext);
    // 20230104105917_filename.pn

    echo '<br>';

    echo sprintf('%0.1s_%0.1s.%0.1s', date("YmdHis"), $filename, $ext);
    // 2_f.p

    ?>

  


 PDO::bindParam() 

PDO::PARAM_STR / PDO::PARAM_INT / PDO::PARAM_BOOL 내부작동

PDO::PARAM_STR : converts whatever you give it to a string except null.

PDO::PARAM_INT : converts bools into longs

PDO::PARAM_BOOL : converts longs into bools

https://stackoverflow.com/questions/833510/php-pdobindparam-data-types-how-does-it-work 


PHP PDO의 bindParam와 bindValue의 차이 

bindParam(참조 복사) - 값 직접입력 불가(참조 대상 변수명 만 가능) 

bindValue(값 복사) - 값 직접입력 가능

$stmt->bindParam(':status', strval($uploadModel->status));  [X]
 $stmt->bindValue(':status', strval($uploadModel->status));  [O]



댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기