Skip to content

Instantly share code, notes, and snippets.

@N-Porsh
Last active December 27, 2015 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N-Porsh/7318827 to your computer and use it in GitHub Desktop.
Save N-Porsh/7318827 to your computer and use it in GitHub Desktop.
PHP: MySQLi connection template
<?php
/* CONFIG */
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_DATABASE", "my_db");
/* CONNECTION */
$link = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
/* change character set to utf8 */
if (!mysqli_set_charset($link, "utf8"))
printf("Error loading character set utf8: %s\n", mysqli_error($link));
/* CLOSE CONNECTION */
mysqli_close($link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment