Page 1 of 1

progammatically create db through cpanel not working

Posted: Tue Sep 14, 2010 8:57 am
by cneeds
Hi

This is supposed to create a MySQL database called test, using cpanel hosting:

Code: Select all

$execute = execCommand("http://cneeds:somepassword@inandrias.com:2082/frontend/x3/sql/adddb.html?db=test");
but doesn't.

Can any body please tell me why...

Chris

Oops! I left out some code:

Code: Select all

function execCommand($command) {
  global $curl_path;

  if (!empty($curl_path)) {
    return exec("$curl_path '$command'");
  }
  else {
    return file_get_contents($command);
  }
}

.
.
.

	$curl_path = "";  // coz I don't know how to use this!!
	$execute = execCommand("http://cneeds:somepassword@inandrias.com:2082/frontend/x3/sql/adddb.html?db=test");

This returns
Not Found

The server was not able to find the document (./frontend/x3/sql/adddb.html) you requested.
Please check the url and try again. You might also want to report this
error to your web hosting provider.

cpaneld/11.25 Server at inandrias.com
When I make $curl_path = '/usr/bin/curl'; I don't get any errors but I also don't get any database!

Chris

Re: progammatically create db through cpanel not working

Posted: Tue Sep 14, 2010 2:04 pm
by bradbury
the error is telling you that the route to your directory is incorrect. you should check to see where the sql database is located within frontend. Also I would try to make a php file to create the database if this isnt working or use phpmyadmin.

Re: progammatically create db through cpanel not working

Posted: Tue Sep 14, 2010 3:40 pm
by cneeds
Thank you.
bradbury wrote:the error is telling you that the route to your directory is incorrect. you should check to see where the sql database is located within frontend. Also I would try to make a php file to create the database if this isnt working or use phpmyadmin.
I confess that I don't know how to find out where sql is located within the frontend on my server. What would I look for?

I need this in a script because I want to create databases in response to certain user requests. I am able to create them with phpmyadmin but that's not the object here.

Chris

Re: progammatically create db through cpanel not working

Posted: Tue Sep 14, 2010 8:47 pm
by califdon
cneeds wrote:I need this in a script because I want to create databases in response to certain user requests. I am able to create them with phpmyadmin but that's not the object here.

Chris
It's almost a certainty that you are starting with an extremely bad design. You almost NEVER need to create databases based on user response! If you want help with your basic concept, we can try to help you. In the meantime, I recommend that you read some tutorials on the design of relational databases.

Re: progammatically create db through cpanel not working

Posted: Wed Sep 15, 2010 5:51 am
by cneeds
califdon wrote:It's almost a certainty that you are starting with an extremely bad design. You almost NEVER need to create databases based on user response! If you want help with your basic concept, we can try to help you. In the meantime, I recommend that you read some tutorials on the design of relational databases.
Hi

I agree with you. How would you solve this scenario?

We are offering users software to run their businesses. This software runs in php and uses mySQL databases for various reasons that we can discuss later. So each user company may elect to run one or more of our products. Clearly we need to keep each of these products in a separate database designed for that specific product.

Would you keep all the user company's data in each product database? That has a number of problems, the most important being, if the db crashes so do all the users of that product.

Please advise how you would resolve this.

Chris

Re: progammatically create db through cpanel not working

Posted: Wed Sep 15, 2010 11:23 am
by califdon
Whoa! That's a major strategic issue that I am not prepared to advise you on. You're talking about a meta-database to serve multiple divergent requirements. Last year I served as an alpha tester for a start-up doing essentially what you described, but they have been working on it for several years and have a programming staff that includes some heavy-weight talent, including at least one name that you would immediately recognize. They have probably soaked several million dollars into searching for the right architecture and developing the system, which was launched early this summer. Are you prepared to invest that kind of effort and time and money?

Re: progammatically create db through cpanel not working

Posted: Wed Sep 15, 2010 12:58 pm
by cneeds
califdon wrote:Whoa! That's a major strategic issue that I am not prepared to advise you on. You're talking about a meta-database to serve multiple divergent requirements. Last year I served as an alpha tester for a start-up doing essentially what you described, but they have been working on it for several years and have a programming staff that includes some heavy-weight talent, including at least one name that you would immediately recognize. They have probably soaked several million dollars into searching for the right architecture and developing the system, which was launched early this summer. Are you prepared to invest that kind of effort and time and money?
hehe, sometimes the simple solution is evaded by the complexity of the viewers.

I am an old hand in the software game, I wrote a spreadsheet programme in machine code before Mr Gates started his version of DOS.

I have written more end user applications than I can remember. So now I want to make all that knowledge available as a legacy to my family and friends. Problem is, I've never used web tools so now I'm struggling with what should really be simple issues...

Chris

Re: progammatically create db through cpanel not working

Posted: Wed Sep 15, 2010 1:53 pm
by califdon
cneeds wrote:hehe, sometimes the simple solution is evaded by the complexity of the viewers.

I am an old hand in the software game, I wrote a spreadsheet programme in machine code before Mr Gates started his version of DOS.

I have written more end user applications than I can remember. So now I want to make all that knowledge available as a legacy to my family and friends. Problem is, I've never used web tools so now I'm struggling...

Chris
I certainly give you your due (I'm an old-timer, myself), but I'd say the issue here is not the web tools, but the strategic design for storing your data. These guys at the start-up are not novices, either, they probably have a combined experience of in excess of a hundred years, and it took them several years of intense collaboration to develop their product. They now have some enterprise customers, as well as many smaller ones. I would caution you not to underestimate the challenge of selecting a storage strategy.

Re: progammatically create db through cpanel not working

Posted: Wed Sep 15, 2010 2:13 pm
by cneeds
califdon wrote:I certainly give you your due (I'm an old-timer, myself), but I'd say the issue here is not the web tools, but the strategic design for storing your data. These guys at the start-up are not novices, either, they probably have a combined experience of in excess of a hundred years, and it took them several years of intense collaboration to develop their product. They now have some enterprise customers, as well as many smaller ones. I would caution you not to underestimate the challenge of selecting a storage strategy.
I agree.

:offtopic: just a tad... The secret (as I'm sure you know) is to not get too complex in the initial phases. leave out all the nice to haves and concentrate on the main thread.

And above all don't let anyone touch it that hasn't got a serious amount of experience under their belt. My best test of this is to give all applicants some really bad code and ask them to change one specific issue. Broadly there are two responses: those who try to fix everything and those who do what you ask. Given enough time they may even come back with a list of "possible problems". No matter how bad a piece of code looks, don't fix it unless its in the mandate and the "fix" is gonna be followed by some serious testing.
___

But that's not solving my problem. :banghead:

Chris

Re: progammatically create db through cpanel not working

Posted: Thu Sep 16, 2010 5:21 am
by stuartr
Which browser are you using to test it?

I tried it with my Cpanel and using IE 8.0 I got the same error message. Checking on the web, it appears that IE no longer supports the passing of usernames and passwords within the URL
By default, versions of Windows Internet Explorer that were released starting with the release of security update 832894 do not support handling user names and passwords in HTTP and HTTP with Secure Sockets Layer (SSL) or HTTPS URLs. The following URL syntax is not supported in Internet Explorer or in Windows Explorer:
http(s)://username:password@server/resource.ext
I thne tried it on Chrome and it appears to work - having said that, it looks like you might need to pass a database name as a variable as calling the link with addb.html at the end resulted in a message that a database had been created with a blank name - it hadn;t so I guess the name is needed. I then tried passing ?dbname=test appended to the URL but still got the same message.

Using wizard1.html instead of addb.html was more successful in that it starts the add database wizard, but without knowing your potential clients, its impossible to know whether this could provide a solution?

Alternatively have you looked at simply issuing mysql commands through PHP once you have connected to the DB server? something along the lines of

Code: Select all

$createSQL = sprintf("CREATE DATABASE $database_conndb1");

$Result1 = mysql_query($createSQL, $conndb1) or die(mysql_error());

  mysql_select_db($database_conndb1, $conndb1);

  $insertSQL = sprintf("CREATE TABLE people (
                  id int UNIQUE NOT NULL,
	  first_name varchar(40),
	  surname varchar(50),
	  PRIMARY KEY(id))"
       );

  $Result1 = mysql_query($insertSQL, $conndb1) or die(mysql_error());
Having said all that, and moving to the question around allowing a user to directly create a database, this would worry me as this implies some form of access rights to create/amend databases and internal structures on scripts available to the public.

Could you instead create a number of empty databases, pre-populated with tables, indexes etc, and simply allocate new users to one of these via their signup routines - e.g. by including variables within their user profile for the data-empty database name you have allocated to them, along with their MySQL user name and password? This would ensure that all administration rights are kept internal, with user called scripts only ever needed restricted access rights?

You could automate the allocation of the databases by simply holding a database of all the precreated dbs, along with assigned user details, and then use your signup scripts to assign the next empty db in your control table to the user in question. At least this way the db is available as soon as teh user signs up, rather than you having to create it "on-demand"

Re: progammatically create db through cpanel not working

Posted: Thu Sep 16, 2010 6:43 am
by cneeds
Hi Stuart

This is a well thought out response. Thank you.

I like your idea of pre-created databases and I will definitely consider that as a potential option. It's major downside (for a purist like me) will be in the naming convention I was planning: user_application, but that's not a show stopper.
___

If I did ever get the automatic creation of the database to work it must be completely transparent to the user.
___

No, not ie anything, I was using mozilla firefox but I guess they've had to close up the same security holes. As someone here said, security is not about "it never happened to me". security is about "could it happen to anyone?".
___

On the cpanel forum a really helpful dude has given me some api functions to read up and try. I'll look into them later. If I come right I will definitely update you with the "secret"! More arrows in your already very helpful quiver!

Thanks again.

Chris