0

My localhost sql is too big.

Now I want to add another remote mysql.

Can Anyone set remote mysql in following local mysql connection?

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"

#Localhost mysql: Make it only read

$hostname_saha = "localhost";
$database_saha = "bdwebstk_1a";
$username_saha = "bdwebstk_1a";
$password_saha = "111111111111"; 

#remote mysql : Plesae make it read and write

$hostname_saha = "xx.yy.zz.zz";
$database_saha = "horjecom_aw";
$username_saha = "horjecom_aw";
$password_saha = "000000000000000000"; 

$saha = mysqli_connect($hostname_saha, $username_saha, $password_saha, $database_saha) or trigger_error(mysqli_error($saha),E_USER_ERROR); 

mysqli_set_charset( $saha, 'utf8');

?>
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

-1

You have to create a separate connections for each of your SQL Server - preferably in separate fiels.

I would strongly recommend naming your connection names from the business pourpose that they will serve. The other strong recommendation for you is to store your configuration files outside of the codebase https://stackoverflow.com/a/3724607/3711660

File localhost_sql.php

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"

#Localhost mysql: Make it only read

$hostname_saha = "localhost";
$database_saha = "bdwebstk_1a";
$username_saha = "bdwebstk_1a";
$password_saha = "111111111111"; 

$sqlcon_localhost= mysqli_connect($hostname_saha, $username_saha, $password_saha, $database_saha) or trigger_error(mysqli_error($saha),E_USER_ERROR); 

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

file remote_sql.php

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"

#Localhost mysql: Make it only read


$hostname_saha = "66.96.566.53";
$database_saha = "horjecom_aw";
$username_saha = "horjecom_aw";
$password_saha = "000000000000000000"; 


$sqlcon_remote= mysqli_connect($hostname_saha, $username_saha, $password_saha, $database_saha) or trigger_error(mysqli_error($saha),E_USER_ERROR); 

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

Then use it in another file as below

require('remote_sql.php');
$result = mysqli_query($sqlcon_remote, "SELECT DATABASE()")
Toumash
  • 1,077
  • 11
  • 27
  • Where I will put this code? require('remote_sql.php'); $result = mysqli_query($sqlcon_remote, "SELECT DATABASE()") Here full code of result https://www20.zippyshare.com/v/dANfYkU7/file.html please tell me – Md Rakib Khan Nov 13 '20 at 10:44
  • You are already including the connection in the first line. `` - thats good, you can keep it in the already exising file, but split the declariations by variable names or create a separate Connections/saha_remove.php file and then require it in your main file :) – Toumash Nov 13 '20 at 10:54
  • I put in number following way but got eror See my code https://www20.zippyshare.com/v/dANfYkU7/file.html – Md Rakib Khan Nov 13 '20 at 11:01
  • There is no error yet. I want to connect multi remote sql in localhost php script. My localhost sql size too big. Now I want localhost will only read data from sql. But remote mysql will read and write . Thus , I want add multi remote sql in my site. In above I given above my localhost mysql details and remote. – Md Rakib Khan Nov 13 '20 at 14:28
  • And my code solves your problem :P The problem was that you had only one connection, but you need 2 separate ones. Are you talking about master/slave configuration or what? https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql – Toumash Nov 16 '20 at 16:27