Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:17:30+00:00 2026-06-03T23:17:30+00:00

I have 2 connection database (MySQL) in different host like this: //database 1 $dbhost=’localhost’;

  • 0

I have 2 connection database (MySQL) in different host like this:

//database 1
$dbhost='localhost';
$dbuser='user1'; 
$dbpass='pass1';
$dbname='dbname1';

//database 2
$dbhostams='192.168.16.3';
$dbuserams='user2';
$dbpassams='pass2';
$dbnameams='dbname2';  

function dbconnection($dbhost,$dbuser,$dbpass,$dbname){
    if(!mysql_connect($dbhost,$dbuser,$dbpass)){
        echo "Error occure on opening connection or database. Period.";
    }else{
        if(!mysql_select_db($dbname)){
            echo "Error occure on select databases !";
        }
    }
}
function dbconnectionams($dbhostams,$dbuserams,$dbpassams,$dbnameams){
    $cxn = mysql_connect($dbhostams,$dbuserams,$dbpassams,$dbnameams);
    if( $cxn === FALSE ) {  
        die('mysql connection error: '.mysql_error()); 
    }else{
        if( !mysql_select_db($dbnameams) ){
            echo "Error occure on select databases !";
        }
    }
}

when i use:

dbconnection($dbhost,$dbuser,$dbpass,$dbname);

at my page code, and use:

dbconnectionams($dbhostams,$dbuserams,$dbpassams,$dbnameams);

at another line of code in same page, error occured, like this:

Warning: Access denied for user: 'apache@localhost' (Using password: NO) in
/home/firman/html/fdrsimpeg/sdm-aam/include/dbclass.php on line 17

Warning: MySQL Connection Failed: Access denied for user: 'apache@localhost'
(Using password: NO) in /home/firman/html/fdrsimpeg/sdm-aam/include/dbclass.php
on line 17

mysql connection error: 

what must i do to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:17:33+00:00Added an answer on June 3, 2026 at 11:17 pm

    Your global variables ($dbhost, $dbuser, etc.) are not within the scope of your function calls; for example, if those function calls take place within another function, you will need to declare the variables within the function with the global keyword in order to access them (otherwise PHP thinks you’re referring to different variables of the same name that are local to the function):

    function foo() {
      global $dbhost, $dbuser, $dbpass, $dbname;
      dbconnection($dbhost,$dbuser,$dbpass,$dbname);
    }
    

    Read more on PHP variable scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to a different machine: $this->_connection = new PDO(mysql: host=MYSQL_SERVER; dbname=MYSQL_DATABASE,MYSQL_USER,
I am connecting a MYSQL database through hibernate and i seem to have processes
I have a database connection which takes an input from the querystring to access
I'm trying to get to grips with regular expressions: I have a database connection
I am trying to access database from a Class Library Project. I have connection
I know I have that my connection to the database works, and a test
I have a global header and footer that has a Database connection and a
I have recently changed my web app to create a database connection per command
My problem involves checking if I have a valid database connection before reading from
All, I am using the VS2010 database connection dialog that Microsoft have released (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.