These are the commands to connect to a remote database.
Ideally this php file should be stored in a secure folder

Call it mysql_connect.php


<?php

DEFINE ('DB_USER', 'username');

DEFINE ('DB_PASSWORD', 'password');

DEFINE ('DB_NAME', 'sitename');

DEFINE ('DB_HOST', 'mysqldb.yoursite.com');

////// OR

////// DEFINE ('DB_HOST', 'localhost');

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('could not connect to mySQL: '. mysql_error() );

@mysql_select_db (DB_NAME) OR die ('could not select the database: ' . mysql_error() );

?>

These are the commands to retrieve information from a specific database in a separate code (index.php or login.php, for example)
You will call the external file 'mysql_connect.php' stored in a secure folder.


<?php

require_once('mysql_connect.php');

$value1 = "username";

$value2 = "userpassword";

$id = $_GET['id'];

$query = "SELECT " . $value1 . "," . $value2 . " FROM login";

/// $query = "SELECT " . $value1 . "," . $value2 . " FROM login WHERE id LIKE '$id' ";

$result = mysql_query($query) or die('cannot execute the search' . mysql_error());

$totalNum = mysql_num_rows($result);

while ( $row = mysql_fetch_array($result)) {

echo $row[$value1] . "<br /> \n";

echo $row[$value2] . "<br /> \n";

}

?>