Skip to content

Instantly share code, notes, and snippets.

@alfredbez
Created April 4, 2013 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredbez/5309941 to your computer and use it in GitHub Desktop.
Save alfredbez/5309941 to your computer and use it in GitHub Desktop.
PHP: Create Mysql Connection
<snippet>
<content><![CDATA[
/********************************/
/* MySQL Connection */
/********************************/
if( $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ){
$mysqlhost="${1:localhost}";
$mysqluser="${2:user_remote}";
$mysqlpwd="${3:password_remote}";
$mysqldb="${4:db_name_remote}";
}
else{
$mysqlhost="${5:localhost}";
$mysqluser="${6:user_local}";
$mysqlpwd="${7:password_local}";
$mysqldb="${8:db_name_local}";
}
$connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd)
or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db($mysqldb, $connection)
or die("Konnte die Datenbank nicht waehlen.");
mysql_query("SET NAMES utf8");
]]></content>
<tabTrigger>mysql_connection</tabTrigger>
<scope>source.php</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment