duangao7133 2015-10-07 12:53
浏览 52

使用PHP通过cPanel创建mysql DB并导入* .sql文件

I want to create a DB for each user who wants to register to my Web-app. When i try this local everything perfectly works. A User can register with his email and pw. A DB is created and a import.sql file is imported so that the DB created for the User is empty on data but the tables and realtioships are given.

My Host uses cPanel and phpMyAdmin to create DB and db-user. I want to do this with php like i do it local. Does anyone have an idea how i get this done?

I've already searched and tryed stuff out but nothing works for me.

If possible some explanations on cPanel maybe would be enough.

  • 写回答

1条回答 默认 最新

  • dscrn1974 2016-01-10 04:26
    关注
                <?php
                require("xmlapi.php"); // this can be downlaoded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
                $xmlapi = new xmlapi("cpanlel host name");   
                $xmlapi->set_port( 2083 );   
                $xmlapi->password_auth('cpanel username','cpanel passsword');    
                $xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false 
    
                $cpaneluser='cpanel username';
                $databasename="something";
                $databaseuser="database username";
                $databasepass= 'database password';
    
                //create database    
                $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));   
                //create user 
                $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));   
                //add user 
                $addusr = $xmlapi->api1_query($cpaneluser, 'Mysql', 'adduserdb', array('' . $databasename . '', '' . $databaseuser . '', 'all'));
                ?>
    

    Using the above code you will be able to create new database, add new user to database and give all access to user on database.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?