The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding user to database - error

Discussion in 'cPanel Developers' started by ManXP, Apr 29, 2009.

  1. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    I'm using cpanel API (doing simple post with PHP/CURL) to create new MySQL database, username, and add his user to database.

    My API query looks like:

    PHP:
    user=$cpanel_username&xmlin=".urlencode("<cpanelaction><module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>".$cpanel_username."_$mysql_database</args><args>".$cpanel_username."_$mysql_username</args><args>ALL</args></cpanelaction>
    New DB gets created, new user gets created, and user is added to database. But I always get "Warning: mysql_connect() [function.mysql-connect]: Access denied" errors, so I believe MySQL user is not added to database correctly (but cPanel displays it's added to database) or permissions are wrong.

    Any ideas, please?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Can you just echo out what URL your script is actually sending to the server. I just want to ensure I'm debugging API issues rather than PHP issues.

    Please don't try to guess what your script is sending to the server, please echo the actual content of what it's sending to the server - though feel welcome to substitute usernames and passwords as this forum is publicly visible.
     
  3. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    OK, here is complete query:

    PHP:
    http://cpanel_username:cpanel_password@domain.com:2082/xml-api/cpanel?user=cpanel_username&xmlin=<cpanelaction><module>Mysql</module><func>adduserdb</func><apiversion>1</apiversion><args>mysql_database</args><args>mysql_username</args><args>ALL</args></cpanelaction>
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    In your script, are you relying on this URL to also handle authentication for you? Or are you doing HTTP authentication before calling this URL?

    Also, does mysql_ represent the cPanel username followed by _?
     
  5. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    Yes, this URL also does authentication.

    And yes, mysql_ represents the cPanel username followed by _
     
  6. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    cPanelDavidG, I'm extremely sorry for wasting your time - I have found and fixed this problem.

    This API reqeust works perfectly, I just didn't see that I forgot to modify auto installer script and script was using format like "database" instead of "cpanelusername_database", so it was displaying errors even after adding user to database.

    Once again, I'm sorry.
     
  7. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hehe, no big deal, it happens to all of us at some point :).
     
Loading...

Share This Page