PHP Source Codes

查詢MySQL的樣板(645 bytes,2020-05-24)

查詢的架構稍稍不一樣,以下的程式碼也請依需求修改。
<?php
     /* Bind parameters. Types: s = string, i = integer, d = double,  b = blob */
     $host = "p:192.168.0.11"; //請填入可以存取的主機IP,p:表示使用連接池(Pooled Connection)
     $user = "root";           //請填入帳號
     $pass = "thePassword";    //請填入密碼
     $dbnm = "theDatabase";    //請填入資料庫名稱
     $conn = new mysqli($host, $user, $pass, $dbnm);
     $sn = 1;
     $sql1 = "SELECT * FROM `users` WHERE sn = ?";  //請依需求改寫
     $stmt = $conn->prepare($sql1);
     $stmt->bind_param('i',$sn);
     $stmt->execute();
     $stmt->bind_result($sn,$name,$mail,$home,$message); //請依需求改寫
     while($stmt->fetch())
     {
         //請依需求改寫
         echo $sn." , ".$name." , ".$mail." , ".$home." , ".$message;
     }
     $stat->close();
     $conn->close();
  ?>
  
上述程式碼,使用http://hilite.me/來渲染PHP的關鍵字,再根據dark style調整部分的顏色。

新增MySQL的樣板(662 bytes,2020-05-24)

分享一個常用的PHP程式碼,用於操作mysql資料庫。若要修改或刪除,請依需求調整$sql1等相關變數。
<?php
     /* Bind parameters. Types: s = string, i = integer, d = double,  b = blob */
     $host = "p:192.168.0.11"; //請填入可以存取的主機IP,p:表示使用連接池(Pooled Connection)
     $user = "root";           //請填入帳號
     $pass = "thePassword";    //請填入密碼
     $dbnm = "theDatabase";    //請填入資料庫名稱
     $H = 0;
     $C = 0;
     $F = 0;
     if (isset($_GET["H"]) && !empty($_GET["H"]) && is_numeric($_GET["H"])) $H = $_GET["H"];
     if (isset($_GET["C"]) && !empty($_GET["C"]) && is_numeric($_GET["C"])) $C = $_GET["C"];
     if (isset($_GET["F"]) && !empty($_GET["F"]) && is_numeric($_GET["F"])) $F = $_GET["F"];
     $conn = new mysqli($host, $user, $pass, $dbnm);
     $sql1 = "insert into pointStatus(locationPoint, H, C, F) values(0, ?, ?, ?)"; //請依需求改寫
     $stat = $conn->prepare($sql1);
     $stat->bind_param("ddd",$H, $C, $F); //請依需求改寫
     $stat->execute();
     $stat->close();
     $conn->close();
?>
上述程式碼,使用http://hilite.me/來渲染PHP的關鍵字,再根據dark style調整部分的顏色。