Hi All,
Until now, I manually create new databases for new customers using PHPmyAdmin. Basically, I import the tables from an existing “dummy” database.
I then HAVE to add a user to the database or no one can access the database.
I would like to explore the possibility of creating a new database automatically. I mean this to happen after a user has subscribed to the application.
After the sale has taken place, I add all of their details into the users table in the admin database.
This is the code, I was experimenting with to create a new database and add a table.
It does not seem to work, where it is saying that the table exists, so it seems that it is not connecting to the newly created “blank” database.
Can anyone suggest where I am going wrong?
Thanks
Tony
$my_usr_database = “test_00008”;
$sql = “CREATE DATABASE $my_usr_database”;
sc_exec_sql($sql);
// this works fine and creates the database
$arr_conn = array();
$arr_conn[‘user’] = “my_user_name”; // credentials in MySQL
$arr_conn[‘password’] = “my_password”; // credentials in MySQL
$arr_conn[‘database’] = $my_usr_database;
if (!empty($my_usr_database))
{
sc_connection_edit(“conn_mysql”,$arr_conn);
$sql = "CREATE TABLE `ledger_codes` (
`gl_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`gl_code` INT(4) NOT NULL,
`gl_name` VARCHAR(60) NOT NULL,
`gl_type` INT(11) UNSIGNED DEFAULT NULL,
`gl_GST_YN` VARCHAR(1) DEFAULT NULL,
`gl_bastypeid` INT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`gl_id`),
UNIQUE KEY `key_glcode` (`gl_code`),
KEY `key_glcodetype` (`gl_type`),
KEY `key_bastype` (`gl_bastypeid`)
)";
sc_exec_sql($sql); // This fails and ssays it already exists
}