PHP Classes

File: Example.SelectSingleRow.php

Recommend this page to a friend!
  Classes of Dustin Ruckman   DB Access using PDO   Example.SelectSingleRow.php   Download  
File: Example.SelectSingleRow.php
Role: Example script
Content type: text/plain
Description: Example showing how to select a single row of data.
Class: DB Access using PDO
Query MySQL tables with prepared queries using PDO
Author: By
Last change: My variable names were wrong
Date: 9 years ago
Size: 503 bytes
 

Contents

Class file image Download
<?php

require('path/to/DatabaseAccess.Class.php');

$DbAccess = new DatabaseAccess("yourHost", "dbName", "dbUser", "dbUserPassword");

$ID = "1000"; // Some ID to select

$DbAccess->PrepareStatement("SELECT * FROM `UserAccounts` WHERE `ID` = :ID");
$DbAccess->BindParameter(":ID", $ID);
$userData = $DbAccess->ExecuteQuery_Get();

// Test that something was returned
if (count($userData) < 1)
    return;

// Note that data is always returned as an array of arrays
var_dump($userData[0]);