jaxdevil Posted February 10, 2009 Share Posted February 10, 2009 I have a code snippet which is supposed to create a database, add a user to MySQL, and add that user to the new database with all privileges. I am copying it below. It is creating the new database, but not creating the user or adding it to the database. Can anyone tell what I am doing wrong on there? Oh yeah, the final $result I added is to a page that is a seperate query altogether that inserts the tables and data, but that is run last so I don't think that is affecting the user creation. Here is the code (I changed the username, password, and URL to dummy data): ############################################################### # cPanel Database Creator 1.2 ############################################################### # Visit http://www.zubrag.com/scripts/ for updates ############################################################### // cPanel username (you use to login to cPanel) $cpanel_user = "username"; // cPanel password (you use to login to cPanel) $cpanel_password = "xxxxxx"; // cPanel domain (example: mysite.com) $cpanel_host = "somedomain.com"; // cPanel theme/skin, usually "x" // Check http://www.zubrag.com/articles/determine-cpanel-skin.php // to know it for sure $cpanel_skin = "x"; // Script will add user to database if these values are not empty // User wil have ALL permissions $db_name = $u['login']; $db_username = $u['login']; $db_userpass = 'xxxxxx'; // Update this only if you are experienced user or if script does not work // Path to cURL on your server. Usually /usr/bin/curl $curl_path = "/usr/local/bin/curl"; ////////////////////////////////////// /* Code below should not be changed */ ////////////////////////////////////// function execCommand($command) { global $curl_path; if (!empty($curl_path)) { return exec("$curl_path '$command'"); } else { return file_get_contents($command); } } // escape db name $db_name = escapeshellarg($db_name); // will return empty string on success, error message on error $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/adddb.html?db=$db_name"); // create user $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/adduser.html?user=$db_username&pass=$db_userpass"); // assign user to database $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/x/sql/addusertodb.html?user=$cpanel_user_$db_username&db=$cpanel_user_$db_name&ALL=ALL"); // insert tables and data $result .= execCommand("http://$cpanel_host/members/dbstructure.php?acct=$db_name"); Quote Link to comment Share on other sites More sharing options...
jaxdevil Posted February 10, 2009 Author Share Posted February 10, 2009 I figured it out. The problem was with escapeshellarg on $db_name , it places single quotes around the variable so it was screwing up the execution of the page. I also switched the last three $result to their own functions, and used file_get_contents() for them instead of CURL. I only used curl on the first one. I don't think those were working in CURL because of the ampersands they contained. It works perfect now. I plugged this into the aMember signup page so when a user signs up a new database is created for them and when they loggin they are using their own database, it also uplaods the structure and default data to their new database. Problem solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.