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.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮