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
https://forums.phpfreaks.com/topic/251061-validation-of-new-mysql-user-via-php/
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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.