Here is the code I use for connecting to a mysql database on localhost (xampp on win 7) and on remote server.
Everything works fine, but now I need to create a connection from localhost to a remote database so I can change remote tables by working on local files.
I'm not sure where to start, but suppose the existing code is a start point.
Any help?
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (strpos($url, 'localhost') == true) {
define('DBHOST','localhost');
define('DBNAME','flash');
define('DBUSER','root');
define('DBPASS','');
}
else {
define('DBHOST','...');
define('DBNAME','...');
define('DBUSER','...');
define('DBPASS','...');
}
try {
$db = new PDO("mysql:host=".DBHOST."; dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (PDOException $e) {
echo $e->getMessage();
exit;
}
$db->query('SET character_set_client = "utf8"');
$db->query('SET character_set_results = "utf8"');
$db->query('SET collation_connection = "utf8_general_ci"');
error_reporting(E_ALL);
ini_set('display_errors', 'on');