0
<?php
$user = substr(md5(rand()),0,16);
$pass = substr(md5(rand()),0,20);
$query = "CREATE USER '{$user}'@'%' IDENTIFIED BY '{$pass}'; 
GRANT USAGE ON * . * TO '{$user}'@'%' IDENTIFIED BY '{$pass}' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; 
CREATE DATABASE IF NOT EXISTS `{$user}`; 
GRANT ALL PRIVILEGES ON `{$user}` . * TO '{$user}'@'%';";
mysql_connect("***.****.info", "***", "****") or die(mysql_error());
mysql_query($query) or die(mysql_error());
?>

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GRANT USAGE ON *.* TO '78eb50407b017587'@'%' IDENTIFIED BY '4fa70f7cc25ccf9dc9dd' at line 1.

Anyone know what's going on here

Update I removed identified by and it did nothing. Any other suggestions?

macintosh264
  • 983
  • 2
  • 11
  • 27

1 Answers1

2

mysql_query() doesn't support multiple query. Do the query one by one.

mysql_connect("***.****.info", "***", "****") or die(mysql_error());
$query1 = "CREATE USER '{$user}'@'%' IDENTIFIED BY '{$pass}';";
$query2 = "GRANT USAGE ON * . * TO '{$user}'@'%' IDENTIFIED BY '{$pass}' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;";
$query3 = "CREATE DATABASE IF NOT EXISTS `{$user}`;";
$query4 = "GRANT ALL PRIVILEGES ON `{$user}` . * TO '{$user}'@'%';";
mysql_query($query1) or die(mysql_error());
mysql_query($query2) or die(mysql_error());
mysql_query($query3) or die(mysql_error());
mysql_query($query4) or die(mysql_error());

But, given the structure of your query, I would suggest you to do a transactions query. You can read more about it, here:

Community
  • 1
  • 1
ariefbayu
  • 21,849
  • 12
  • 71
  • 92
  • Thanks for such a great answer to such a stupid question! I love this site, and all the great members on it. I wish I could give people like you more than just an upvote and accept. – macintosh264 Jun 20 '12 at 03:57