最初に、データベース接続が必要です。 pdo:
mysqli_connect()
<code class="php"><?php $conn = mysqli_connect("localhost", "your_username", "your_password", "your_database"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // Prepare the statement $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ?"); // Bind parameters. 's' indicates string type. Adjust as needed for other data types (i, d, b). $stmt->bind_param("ss", $username, $password); // Assign values to parameters $username = $_POST['username']; $password = $_POST['password']; //Important: NEVER directly use user input without sanitization. Consider password hashing instead of storing plain text passwords! // Execute the statement $stmt->execute(); // Bind result variables $stmt->bind_result($id, $username, $email, $password); //Replace with your actual column names // Fetch results while ($stmt->fetch()) { echo "ID: " . $id . "<br>"; echo "Username: " . $username . "<br>"; echo "Email: " . $email . "<br>"; // Avoid echoing the password! } // Close the statement and connection $stmt->close(); $conn->close(); ?></code>を1回
に解析し、提供されたパラメーターを使用してクエリのみを実行するためです。
以上がPHP 7で準備されたステートメントを使用する方法は?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。