SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Error connecting to MySQL Db from Php program

    Hello,

    I am not able to connect to MySQL db running on this new server!

    I a using the same code and procedure as our other servers to connect
    a Php page to MySQL running on same server, but it is not working!
    I get this error message:

    Warning: mysql_connect() [function.mysql-connect]: Host 'www.netdive.com' is not allowed to connect to this MySQL server in /var/www/html/dd.com/db_connex.php on line 3
    Host 'www.netdive.com' is not allowed to connect to this MySQL server

    Notes:
    1- Of course I am providing the correct password for MySQL root of this MySQL, as I am logged into MySQL as root with this password

    2- I also tried netdive.com in the
    mysql_connect('netdive.com', 'root', 'xyzxyz')

    What is going on!

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may be running up against a problem with the MySQL server being prohibited from connecting to from outside a specific IP range/hostname. My MySQL server is like that, too, so what I did was to set up a "clone" MySQL server on my dev system, to make sure that I can test my pages locally. It's not hard to do so, but it's not for the total novice, either (unless you LIKE going bald in a few minutes time. )

    If this is, indeed, the case, perhaps a quick post in the Databases forum can show you the best way to set up your own local DB, and how to populate it with the needed databases/etc.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Actually I realized right after I posted this message that unless specified MySQL will not allow connection from an outside program.

    So there is just a bit of code that I need to either add to my MySQL connect command or change certain settings on MySQL on this server to allow connection from outside.

    Do you know what either of above steps are?

    regards,

    Quote Originally Posted by Dave Morton View Post
    You may be running up against a problem with the MySQL server being prohibited from connecting to from outside a specific IP range/hostname. My MySQL server is like that, too, so what I did was to set up a "clone" MySQL server on my dev system, to make sure that I can test my pages locally. It's not hard to do so, but it's not for the total novice, either (unless you LIKE going bald in a few minutes time. )

    If this is, indeed, the case, perhaps a quick post in the Databases forum can show you the best way to set up your own local DB, and how to populate it with the needed databases/etc.

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Offhand, no. There are factors like where your database is hosted, what it's specific configuration is, etc. Also, I'm no expert when it comes to database management. I only know what I've gone through, and that isn't much, I'm afraid. Heck, when I hear "left outer join", I think someone's trying to glue something to my truck's fender!
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  5. #5
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks anyway.
    But I am surprised no one else knows the answer to this question either
    since I am sure it is such a commonly run into problem!
    Well I guess I need to find a MySQL board that is more heavily trafficked.

    And hey "left outer join" is really cool stuff


    Quote Originally Posted by Dave Morton View Post
    Offhand, no. There are factors like where your database is hosted, what it's specific configuration is, etc. Also, I'm no expert when it comes to database management. I only know what I've gone through, and that isn't much, I'm afraid. Heck, when I hear "left outer join", I think someone's trying to glue something to my truck's fender!

    Anoox search engine volunteer

    www.anoox.com

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So there is just a bit of code that I need to either add to my MySQL connect command
    There is nothing to add if you're connecting from an "outside" host, not allowed to connect.
    change certain settings on MySQL on this server
    That's GRANT query but I doubt you have rights to this command.
    Most of time it's a subject to call hosting support for.

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I a using the same code and procedure as our other servers to connect
    a Php page to MySQL running on same server, but it is not working!
    If i understood correctly, you are in the same server. So why not try just with localhost? Did you try with only with 'localhost'?
    PHP Code:
    mysql_connect('localhost''root''xyz') or die(mysql_error()); 
    Otherwise if you are trying to connect from outside the same server then the database user that you are trying to use must have that privileges.
    Code mysql:
    CREATE USER 'test'@'%' IDENTIFIED BY  '***';
     
    GRANT ALL PRIVILEGES ON * . * TO  'test'@'%' IDENTIFIED BY  '***';
     
    GRANT ALL PRIVILEGES ON  `test\_%` . * TO  'test'@'%';
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that did the Job

    I mean changing the host name just to 'localhost' from netdive.com

    But that is very strange that it is not allowing me to connect
    to netdive.com mysql when I am logging in as root!!!
    I am able to connect to our other servers MySQL in this way!

    But at least I can connect to this MySQL db now and get these urgent
    tasks done and then later find out why it is not allowing me to connect
    normally as a root.


    Quote Originally Posted by rajug View Post
    If i understood correctly, you are in the same server. So why not try just with localhost? Did you try with only with 'localhost'?
    PHP Code:
    mysql_connect('localhost''root''xyz') or die(mysql_error()); 
    Otherwise if you are trying to connect from outside the same server then the database user that you are trying to use must have that privileges.
    Code mysql:
    CREATE USER 'test'@'%' IDENTIFIED BY  '***';
     
    GRANT ALL PRIVILEGES ON * . * TO  'test'@'%' IDENTIFIED BY  '***';
     
    GRANT ALL PRIVILEGES ON  `test\_%` . * TO  'test'@'%';

    Anoox search engine volunteer

    www.anoox.com

  9. #9
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The MySQL server is only configured to accept connections from "localhost". This is not uncommon, and prevents a plethora of security problems. glad to see you got it sorted out.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  10. #10
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No. One can connect to other MySQL servers as we for example already do.
    To be exact I am connecting to multiple other servers that we have
    via the server name and not via 'localhost', but somehow this one server
    was not allowing connection through server name. So as I said I think there
    is something in the MySQL settings that allows this or not. I was hoping someone would have mentioned what that is, but alas no one has and I
    am running these programs from the same server where its MySQL is
    so I can just use the 'localhost' to connect.

    Quote Originally Posted by Dave Morton View Post
    The MySQL server is only configured to accept connections from "localhost". This is not uncommon, and prevents a plethora of security problems. glad to see you got it sorted out.

    Anoox search engine volunteer

    www.anoox.com

  11. #11
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Inside every MySQL database server is a "schema", or, if you will, a type of database, that's internal, more or less, to itself. In this schema is the configuration data that tells the MySQL server (among other things) what usernames can connect to the database from which locations, using what passwords. This is basic MySQL stuff. All servers are configured in various ways. the one YOU are using seems to only allow connections for your username/password combination from localhost. It doesn't matter what other MySQL servers have been configured for. You're not having problems with other servers. You're having problems with THIS one. Please re-consider the wisdom of arguing blindly with those who have knowledge and experience that you seek to gain. I'm glad you can now connect using localhost. Is there anything else we can assist with?
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  12. #12
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Did you actually say:
    "Please re-consider the wisdom of arguing blindly with those who have knowledge and experience that you seek to gain."

    It seems like you completely missed my point, since I was really asking a question to fully understand this discrepancy. But it seems like you really do not have necessary information about MySQL and each and every time you have wasted my time with answers that were anything but right. So kindly do me a favor and do not answer to my questions in future.


    Quote Originally Posted by Dave Morton View Post
    Inside every MySQL database server is a "schema", or, if you will, a type of database, that's internal, more or less, to itself. In this schema is the configuration data that tells the MySQL server (among other things) what usernames can connect to the database from which locations, using what passwords. This is basic MySQL stuff. All servers are configured in various ways. the one YOU are using seems to only allow connections for your username/password combination from localhost. It doesn't matter what other MySQL servers have been configured for. You're not having problems with other servers. You're having problems with THIS one. Please re-consider the wisdom of arguing blindly with those who have knowledge and experience that you seek to gain. I'm glad you can now connect using localhost. Is there anything else we can assist with?

    Anoox search engine volunteer

    www.anoox.com

  13. #13
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'll never trouble you again, once I've had my say.

    first off, I did NOT miss your point, though you have certainly missed mine. And possibly the points of others, as well:

    Quote Originally Posted by WorldNews View Post
    Hello,

    I am not able to connect to MySQL db running on this new server!
    ...
    I get this error message:

    Warning: mysql_connect() [function.mysql-connect]: Host 'www.netdive.com' is not allowed to connect to this MySQL server in /var/www/html/dd.com/db_connex.php on line 3...
    the problem is obvious, at this point. Your server that you are trying to connect to at netdive.com is configured to refuse connections from outside it's local IP range. By trying to connect to that server at netdive.com, you are using it's public IP address, which is 64.34.169.145. Connecting to that same server by using localhost uses the IP address of 127.0.0.1, which is the local loopback address for practically every computer on the planet. Since the server at netdive.com is configured to refuse outside connections, your script got that error message.

    Now, I posted the following reply, which says pretty much the same thing:

    Quote Originally Posted by Dave Morton View Post
    You may be running up against a problem with the MySQL server being prohibited from connecting to from outside a specific IP range/hostname....
    So far, so good. We're still on a friendly basis. Your response:

    Quote Originally Posted by WorldNews View Post
    Hi,

    Actually I realized right after I posted this message that unless specified MySQL will not allow connection from an outside program.

    So there is just a bit of code that I need to either add to my MySQL connect command or change certain settings on MySQL on this server to allow connection from outside.

    Do you know what either of above steps are?

    regards,
    Now I overlooked the misuse of the word "program", figuring that you had to mean "outside address". And since this is a database management problem, and you had not, at this point, indicated that your web server and your mySQL server were on the same IP address, so I indicated that this was outside my ability to advise you further, and I said so:

    Quote Originally Posted by Dave Morton View Post
    Offhand, no. There are factors like where your database is hosted, what it's specific configuration is, etc. Also, I'm no expert when it comes to database management....
    I guess I should have also, at this point, referred you to the database forum, but alas, I failed to do so. I'm sorry. Still no real friction, though.

    Then shrapnel pops in and tries to assist, thouugh he's a bit more cogent than is really necessary, at times.

    Quote Originally Posted by Shrapnel_N5 View Post
    There is nothing to add if you're connecting from an "outside" host, not allowed to connect.

    That's GRANT query but I doubt you have rights to this command.
    Most of time it's a subject to call hosting support for.
    And rajug finally provides the winning answer:

    Quote Originally Posted by rajug View Post
    If i understood correctly, you are in the same server. So why not try just with localhost? Did you try with only with 'localhost'?
    PHP Code:
    mysql_connect('localhost''root''xyz') or die(mysql_error()); 
    ...
    YAY! Problem solved! but for some odd reason it doesn't end there:

    Quote Originally Posted by WorldNews View Post
    Thank you, that did the Job

    I mean changing the host name just to 'localhost' from netdive.com

    But that is very strange that it is not allowing me to connect
    to netdive.com mysql when I am logging in as root!!!
    I am able to connect to our other servers MySQL in this way!
    ....
    Ok, so you mentioned that "it was strange", and this was covered by my earlier post, not to mention shrapnel's post, as well, so I TRY to explain further:

    Quote Originally Posted by Dave Morton View Post
    The MySQL server is only configured to accept connections from "localhost". This is not uncommon, and prevents a plethora of security problems. glad to see you got it sorted out.
    I can see that perhaps my wording was not ideal, since I referred to the MySQL server at netdive.com with a generic "the server". Silly lapse, but common. Yet you seem to think I'm referring to all MySQL servers, which is not the case:

    Quote Originally Posted by WorldNews View Post
    No. One can connect to other MySQL servers as we for example already do.
    To be exact I am connecting to multiple other servers that we have
    via the server name and not via 'localhost', but somehow this one server
    was not allowing connection through server name. So as I said I think there
    is something in the MySQL settings that allows this or not...
    Ok, I realize that I had been a bit too general, so I try to further explain, with more specifics:

    Quote Originally Posted by Dave Morton View Post
    Inside every MySQL database server is a...
    And yes, I was getting a little frustrated, and I took it out on you. And for that I apologize. But all of what I had said was:

    a.) relevant
    b.) correct
    and c.) polite (well, as polite as I could be, at the time. Believe me when I say you would NOT have wanted to be on THIS side of my screen at the time).

    So now I've had my say. May your days be interesting, and your evenings be uneventful.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  14. #14
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do not fight guys. Take every reply and arguments as positive knowledge.

    And regarding the question:
    .....then later find out why it is not allowing me to connect
    normally as a root.
    Normally the provided host names can only be used with that function. See more details:
    http://www.php.net/mysql-connect
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  15. #15
    SitePoint Guru rageh's Avatar
    Join Date
    Apr 2006
    Location
    London, Formerly Somalia
    Posts
    612
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave Morton, I think you have been helpful throughout. You cannot blame yourself for being too general in your answers while the question has not been specific enough. You don't really have to apologise for helping someone. Your answers were not misleading. So the OP's outburst was uncalled for.
    ------------------


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •