[第九週] PHP 與 MySQL 的互動:新增資料


Oct 08, 2020
  • sprintf( $format , $args1 , $args2 , $args3...) 把格式化的字符串寫寫入一個變量中。
    formatargs 是要插入 formatformat)中的百分號(%)符號處,並完成格式化,例如 args1format 的第 1 個 % 位置、args22args3 插入到第 3 個 % 位置 ... 以此類推
    // $format: insert into users(id, username) values(%d, '%s')
    // $args1: 13,插入 %d 處
    // $args2: $username, 插入 %s 處
    // 輸出:insert into users(id, username) values(13, 'Tom')
    $username = 'Tom';
    $sql = sprintf(
      "insert into users(id, username) values(%d, '%s')",
      13,
      $username
    );
    echo $sql;
    






你可能感興趣的文章

Day 3 | Enter max-width

Day 3 | Enter max-width

nmapAutomator - OSCP考試好用的工具

nmapAutomator - OSCP考試好用的工具

【HTML & CSS】學習筆記 #02

【HTML & CSS】學習筆記 #02






留言討論