發表文章

查詢phpMyAdmin資料表資料

<?php $mysqli = new mysqli('localhost', 'root', '20190129app', 'app_record'); //require"conn.php"; mysqli_set_charset($mysqli, "UTF8"); //$sql = "SELECT * FROM location ORDER BY id ASC LIMIT 1";//取第一行 $sql = "SELECT * FROM location ORDER BY id DESC LIMIT 1";//取最後一行 if (!$result = $mysqli->query($sql)) {     // Oh no! The query failed.     echo "Sorry, the website is experiencing problems.";     // Again, do not do this on a public site, but we'll show you how     // to get the error information     echo "Error: Our query failed to execute and here is why: \n";     echo "Query: " . $sql . "\n";     echo "Errno: " . $mysqli->errno . "\n";     echo "Error: " . $mysqli->error . "\n";     exit; } if ($result->num_rows === 0) {     // Oh, no rows! Sometimes that's expected and okay, sometimes  ...

新增資料至資料表

<?php require"conn.php"; $a = $_POST["欄位a名稱"]; $b = $_POST["欄位b名稱"]; //$a = "內容"; $mysql_qry="insert into location (欄位a名稱,欄位b名稱)values('$a','$b')"; if($conn->query($mysql_qry)===TRUE){ //echo "Insert success"; echo "上傳成功"; } else{ echo"Error:".$mysql_qry."<br>".$conn->error; echo"上傳失敗"; } $conn->close(); ?>

如何登入伺服器?

<?php $db_name = "資料表名稱"; $mysql_username = "root"; $mysql_password = "密碼"; $server_name = "127.0.0.1"; $conn = mysqli_connect($server_name,$mysql_username,$mysql_password,$db_name); mysqli_set_charset($conn, "UTF8");//中文化 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> //網頁專用,加於head中間。 if($conn){ //echo"connect success"; } else{echo"connect not success";} ?>