Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Connect to DB
- */
- $host = "localhost";
- $user = "root";
- $pass = "";
- $dbname = "huge";
- try {
- $conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "<span style='color: green;'>Connected successfully.</span><br />";
- }
- catch(PDOException $e) {
- echo "Connection failed: " . $e->getMessage();
- }
- /**
- * Psuedo username
- */
- $username = "Corspiracy";
- /**
- * Test a query...
- */
- $sql = "SELECT * FROM users WHERE user_name = :username";
- /**
- * Prepare the query...
- */
- $stmt = $conn->prepare($sql);
- /**
- * Bind query parameters.
- */
- $stmt->bindParam(":username", $username, PDO::PARAM_STR);
- /**
- * Execute the query
- */
- $stmt->execute();
- /**
- * Fetch results
- */
- $results = $stmt->fetchAll();
- /**
- * Iterate through results...
- */
- foreach($results as $row) {
- echo "{$row['user_name']} is registered already.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement