Jump to content

Validation of new MYSQL USER via PHP


azunoman

Recommended Posts

Hi, long time fan of the phpfreaks.

 

I have a cron job that creates sub/domains using PHP, I received an error creating a sites mysql db username: "Unable to create database: Database user name is invalid."

 

The MYSQL username I was trying to add  was: soloparaafiliado, and is the subdomain name.  Obviously I need to check my generated MYSQL username so that it doesn't get rejected.  I have no requirement that the MYSQL username be the same as the subdomain.

 

Beat around the web looking for some guideline on the allowed formats of a MYSQL username but didn't find anything obvious.  Curious if there any information of valid username format.

 

Any help would be great appreciated.

 

 

Link to comment
Share on other sites

You should be logging the actual mysql_error() [edit: and the actual query statement] so that you know why the query failed.

 

There's nothing in the visible part of that name that would be a problem. You likely have some white-space/non-printing character before or after that string that either should be trimmed off or filtered out.

Link to comment
Share on other sites

Great reply PFMaBiSmAd, thank you!

 

I left out many details in my post and I apologize, I call the PLESK 9 CLI via shell_exec db --create.  I went to the PLESK  panel manager and entered it manually and it worked.  I never really liked using the subdomain name for the db username, I will take this opportunity to use a php rand to create the db username. 

 

sorry marked as resolved...my bad...I will come back and post the sql command

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.