1
I have this config file.
<?PHP
$s_ipserver1 = "10.0.0.101";
$db_porta1 = "3306";
$db_user1 = "user";
$db_password1 = "123456";
$db_name1 = "name";
$s_ipserver2 = "xxx.xxx.xxx.xxx";
$db_porta2 = "3306";
$db_user2 = "user";
$db_password2 = "123456";
$db_name2 = "name";
$s_ipserver3 = "xxx.xxx.xxx.xxx";
$db_porta3 = "3306";
$db_user3 = "user";
$db_password3 = "123456";
$db_name3 = "name";
?>
And I want to turn it into something like this.
<?PHP
$dbL = "1";// Que servidor é este? 1, 2 ou 3.
$s_ipserver1 = "10.0.0.101";
$db_porta1 = "3306";
$db_user1 = "user";
$db_password1 = "123456";
$db_name1 = "name";
$s_ipserver2 = "xxx.xxx.xxx.xxx";
$db_porta2 = "3306";
$db_user2 = "user";
$db_password2 = "123456";
$db_name2 = "name";
$s_ipserver3 = "xxx.xxx.xxx.xxx";
$db_porta3 = "3306";
$db_user3 = "user";
$db_password3 = "123456";
$db_name3 = "name";
$s_ipserver = "$s_ipserver$dbL";
$db_porta = "$db_porta$dbL";
$db_user = "$db_user$dbL";
$db_password = "$db_password$dbL";
$db_name = "$db_name$dbL";
?>
This is one of the link files.
<?PHP
include_once("/pasta/config.php");
$db_host1 = "$s_ipserver1:$db_porta1";
$db_link1 = mysql_connect($db_host1, $db_user1, $db_password1) or die (mysql_error ());
$db_connect1 = mysql_select_db($db_name1, $db_link1);
?>
And I need it to look something like this.
<?PHP
include_once("/pasta/config.php");
$db_host = "$s_ipserver:$db_porta";
$db_link = mysql_connect($db_host, $db_user, $db_password) or die (mysql_error ());
$db_connect = mysql_select_db($db_name, $db_link);
?>
Where is my mistake? All the original files are working perfectly.
You must be a bot, only can :D
– Bruno Augusto
bots don’t find anything extremely ugly and confusing :)
– bfavaretto
As I can not only write "Good", then "Good!" p
– Bruno Augusto
I tried the ugly part and the result was the following error in the PHP Warning link file: mysql_connect(): Unknown Mysql server host '$s_ipserver1' (25) in /folder/connect.php on line 4
– Ricardo Jorge Pardal
@Rjpserver How was your line
$db_link = mysql_connect...
?– bfavaretto
Same as $link = mysql_connect($host, $user, $password) or die (mysql_error ());
– Ricardo Jorge Pardal
Didn’t you adapt my code? Just like I showed you
$servidor = 's_ipserver'. $dbL;
, you need to do it the same way for port, user, etc. Then you can do it$host = $$servidor . ':' . $$porta;
, and only use there$host
when connecting. @Rjpserver– bfavaretto
Yes I adapted and created another file to ensure your changes. I can answer this question with all the code I need so we can make the necessary changes or I have to edit the question ??
– Ricardo Jorge Pardal
@Rjpserver Answer no, and editing the question would change the nature of it. Give me a link with your code in Pastebin.com
– bfavaretto
I never used Pastebin but it is here in TXT format on my server link
– Ricardo Jorge Pardal
$host = $$ipserver . ':'. $$porta;
@Rjpservidor– bfavaretto
Yes I had already tried and the mistake is:
PHP Notice: Undefined variable: $s_ipserver1 in /pasta/connect.php on line 3
PHP Notice: Undefined variable: $db_porta1 in /pasta/connect.php on line 3
PHP Warning: mysql_connect(): Access denied for user '$db_user1'@'localhost' (using password: YES) in /pasta/connect.php on line 4
Access denied for user '$db_user1'@'localhost' (using password: YES)
– Ricardo Jorge Pardal
I’ve already made the change in the link with what I’ve been doing
– Ricardo Jorge Pardal
I don’t know what it could be, @Rjpservidor... :(
– bfavaretto
I’ve done it now as I answer my own question?
– Ricardo Jorge Pardal
Yes, you can reply @Rjp
– bfavaretto
@Rjpserver Seeing your answer touched me on what was wrong with the code you linked: in subconnect.php, use
's_ipserver'. $dbL
, dollar sign at the beginning, and take the dollar sign off the names of the other variables as well. In my opinion it’s still a little cleaner than using theeval
...– bfavaretto