Skip to content

Instantly share code, notes, and snippets.

@sarkarshuvojit
Last active December 6, 2017 20:51
Show Gist options
  • Save sarkarshuvojit/c8169ac9afa3cfb4b733e6977d7a80e9 to your computer and use it in GitHub Desktop.
Save sarkarshuvojit/c8169ac9afa3cfb4b733e6977d7a80e9 to your computer and use it in GitHub Desktop.
Blog demo code
<?php
// connect to database
$con = mysqli_connect('host', 'user', 'password', 'db_name');
// check for connection errors
if(mysqli_connect_errno())
die(mysqli_connect_error());
// function to execute query and automatically check for errors
function query($sql){
$result = mysqli_query($GLOBALS['con'], $sql);
if(!$result){
die(mysqli_error($GLOBALS['con']));
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment