PHP Tutorial

  • 02-Jun-2020
  • 163

<?php 
if($_SERVER['SERVER_NAME']=='localhost'){
mysql_connect('localhost','root', '') or die ('Could not connect to server');
mysql_select_db('name_db') or die ('Database not found2');
$baseurl = "";
}else{
mysql_connect('localhost','root', 'password') or die ('Could not connect to server');
mysql_select_db('name_db') or die ('Database not found');
$baseurl = "";
}
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
?>

<?php
$con = mysql_connect("localhost","root","password");
if (!$con)  {
  die('Could not connect to Database: ' . mysql_error());
  }
mysql_select_db("name_db", $con);
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
?>

<?php 
if($_SERVER['SERVER_NAME']=='localhost'){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "name_db";
}else{
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "name_db";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

mysqli_set_charset( $conn, 'utf8');
?>