实际上我想在使用php运行网页时动态地在我的服务器上创建数据库。当网页代码被执行后,我找到了新创建的数据库,用于创建动态数据库的代码工作正常...
但问题是我无法为该数据库的特定用户分配所需的读写权限。
我尝试了以下代码段:
function createDb($cPanelUser,$cPanelPass,$dbName) {
$buildRequest = "/frontend/x3/sql/addb.html?db=".$dbName;
$openSocket = fsockopen('localhost',2082);
if(!$openSocket) {
return "Socket error";
exit();
}
$authString = $cPanelUser . ":" . $cPanelPass;
$authPass = base64_encode($authString);
$buildHeaders = "GET " . $buildRequest ."\r\n";
$buildHeaders .= "HTTP/1.0\r\n";
$buildHeaders .= "Host:localhost\r\n";
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
$buildHeaders .= "\r\n";
fputs($openSocket, $buildHeaders);
while(!feof($openSocket)) {
fgets($openSocket,128);
}
fclose($openSocket);
}
function createUser($cPanelUser,$cPanelPass,$userName,$userPass) {
$buildRequest = "/frontend/x3/sql/adduser.html?user=".$userName."&pass=".$userPass;
$openSocket = fsockopen('localhost',2082);
if(!$openSocket) {
return "Socket error";
exit();
}
$authString = $cPanelUser . ":" . $cPanelPass;
$authPass = base64_encode($authString);
$buildHeaders = "GET " . $buildRequest ."\r\n";
$buildHeaders .= "HTTP/1.0\r\n";
$buildHeaders .= "Host:localhost\r\n";
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
$buildHeaders .= "\r\n";
fputs($openSocket, $buildHeaders);
while(!feof($openSocket)) {
fgets($openSocket,128);
}
fclose($openSocket);
}
function addUserToDb($cPanelUser,$cPanelPass,$userName,$dbName,$privileges) {
$buildRequest = "/frontend/x3/sql/addusertodb.html?user=".$userName."&db=".$dbName.$privileges;
$openSocket = fsockopen('localhost',2082);
if(!$openSocket) {
return "Socket error";
exit();
}
$authString = $cPanelUser . ":" . $cPanelPass;
$authPass = base64_encode($authString);
$buildHeaders = "GET " . $buildRequest ."\r\n";
$buildHeaders .= "HTTP/1.0\r\n";
$buildHeaders .= "Host:localhost\r\n";
$buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
$buildHeaders .= "\r\n";
fputs($openSocket, $buildHeaders);
while(!feof($openSocket)) {
fgets($openSocket,128);
}
fclose($openSocket);
}
createDb('cpanelusername','cpanelpassword','dbname');
createUser('cpanelusername','cpanelpassword','dbusername','dbpassword');
addUserToDb('cpanelusername','cpanelpassword','dbusername','dbname','&ALL=ALL');
请帮助......