Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Created May 31, 2013 02:59
Show Gist options
  • Save bittersweetryan/5682721 to your computer and use it in GitHub Desktop.
Save bittersweetryan/5682721 to your computer and use it in GitHub Desktop.
<?
require_once '_header.php';
$db = $sql -> OpenSafeConnection(); //see below
$sql = "SELECT firstname FROM jobapplications WHERE firstname = ?";
$query = $db->prepare( $sql );
$name = 'Nicole';
$query->bind_param('s', $name);
$result = $query->execute();
$query->bind_result( $firstname );
while( $query->fetch() ){
echo( $firsname . '<br>' );
}
?>
function OpenSafeConnection(){
$db = new mysqli($this->_VARS["host"], $this->_VARS["login"], $this->_VARS["pass"], $this->_VARS["db"]);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
return $db;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment