CREATE DATABASE through a script in PHP?

1

How could I create a database every time a user, for example, if a company registers in my web system? Type, today, the only thing I have are administrative access data to FTP and database data as host, port ...

How could within an administrative interface create a complete database for a client since CREATE DATABASE? What are the necessary requirements and in which the hosting service could disrupt this procedure?

This curiosity came from the following fact: a company like Conta Azul for example has a whole financial administrative system and I imagine that for each client a new bank with a fresh dump is installed with only the tables but I have no idea how this is done.

In this case, if each client really had a personal database and this database was created through a simple registration of personal and legal information, how to reach the expected result without having to access the hosting or phpmyadmin or any facilitator .

    
asked by anonymous 02.09.2014 / 21:12

1 answer

2

If your user has create create database you can usually execute as the example below:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE my_db';
if (mysql_query($sql, $link)) {
    echo "Database my_db created successfully\n";
} else {
    echo 'Error creating database: ' . mysql_error() . "\n";
}
?>

Of course, the most correct would be to work with the correct bank modeling to use the same bank for several companies.

    
02.09.2014 / 21:43