Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Learning PDO

Featured Replies

Just started to learn PDO and Prepared Statements, been meaning to do this for a while.

 

Just wondering if the following is technically correct, if it's missing anything or whatever?

 

Are there any good tutorials anyone knows that I can read that I may not have found?

 

<?php
try {
$user = 'zend';
$pass = '';

$dbh = new PDO('mysql:host=localhost;dbname=Sites', $user, $pass);

$name = 'adam';

$stmt = $dbh->prepare("SELECT * FROM User WHERE Username = ?");
$stmt -> setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute(array($name));
$row = $stmt->fetch();
?>

<html>
<head>
</head>
<body>
<?php
echo $row['Email'];
echo "<br />";
echo $row['Username'];
?>
</body>
</html>

<?php
$dbh = null;
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}
?>

someone must use prepared statements

cant say i use them as most as alot of guys on here but ur code looks fine to me :) i always do my statements in this mannor though

 

$dbh = new PDO('mysql:host=localhost;dbname=Sites', $user, $pass);

       $name = 'adam';

       $stmt = $dbh->prepare("SELECT * FROM User WHERE Username = :username");
       $row = $stmt->fetch();
       $stmt->execute(":username",PDO::PARAM_STR);

Edited by webdesigner93

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.