Php 在cPanel中动态创建数据库?
database.php-configPhp 在cPanel中动态创建数据库?,php,mysql,codeigniter,cpanel,Php,Mysql,Codeigniter,Cpanel,database.php-config $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'sample', 'password' => 'xxxxxxxxxxx', 'database' => 'db_sample', 'dbdriver' => 'mysqli', 'dbprefix' =&g
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'sample',
'password' => 'xxxxxxxxxxx',
'database' => 'db_sample',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
控制器:
<?php
class Test extends CI_Controller {
public function index() {
$this->load->model('Test_model');
$sample = $this->Test_model->test();
echo $sample;
}
}
?>
是否有我缺少的任何配置设置?
我已经为此挣扎了两天了。我已经发送了一个帮助通知单,但他们只是告诉我,有问题的特权用户和数据库必须在同一个cPanel帐户下(据我所知,他们是)。
示例用户拥有为其启用的所有权限。我们手动设置。检查您的数据库服务器名称。在Serer上,它不能是本地主机。与数据库管理员确认。如消息所述,
'sample'@'localhost'
没有数据库创建权限。您是否确实获得了用户创建数据库的权限?尝试从您的帐户打开控制台并尝试创建数据库。@Vinay在服务器上的服务器名称通常为localhost
,除非以奇怪的方式配置。我忘了告诉您,但未经DB管理员许可,我们无法在服务器上创建新用户。@Vinay基于我在google上找到的内容,我可以在将项目上载到cPanel服务器时使用“localhost”。我不知道还能放些什么,尝试添加端口也没用。
<?php
class Test_model extends CI_Model {
public function test() {
$sql = "SELECT name
FROM company";
$query = $this->db->query($sql);
$num = $query->num_rows();
$this->load->dbforge();
if($this->dbforge->create_database('service_test')) {
$this->db->query("Use service_test");
$this->db->query("CREATE USER 'user1'@localhost IDENTIFIED BY 'admin123';");
$this->db->query("GRANT ALL PRIVILEGES ON service_test.* TO user1@localhost identified by 'admin123';");
return true;
} else {
return false;
}
}
}
?>
Error Number: 1044
Access denied for user 'sample'@'localhost' to database 'service_test'
CREATE DATABASE `service_test` CHARACTER SET utf8 COLLATE utf8_general_ci