How to create databases on mySQL using script (PHP, etc) - php

I am thinking of running a hosted service using Amazon Services (PHP + mySQL). What I like to do is have a site where someone registers, pays PayPal and returns to site where they will get an automated information to their mySQL account. So this mySQL account would only be used by them. They can create tables, etc.
Some questions are:
1) Is there a way to create a new mySQL account and table using a script? (PHP?)
2) Is there any open-source scripts out there that already does this that I can take apart and use?
3) If the above is not a good idea, any other suggestions.
Basically I want them to put files on their local web hosting (Hostgator, Dreamhost, etc) but be able to grab data from my database in Amazon. So I want each user to be limited to their own database and not mess with others. And they need ability to update tables.
Any suggestions & thoughts appreciated!

CREATE DATABASE, CREAT USER and GRANT commands needs a lot of privileges. You should be wary of using such an account in a web script. For one thing if a user is able to figure out your paypal call back URL, there is a possibility that he can post data directly to that url and cause mischief.
What I would suggest is for you to enter the details of the database and user accounts that need to be created into a queue (maybe held in a mysql table), and to run a scheduled task (maybe cron) to create them in the background. When you do that the script does not need to have access to an account with a high level of privileges.
As to how exactly a database and user account can be created; well you can treat them like any other queries.
CREATE USER: http://dev.mysql.com/doc/refman/5.1/en/create-user.html
CREATE DATABASE: http://dev.mysql.com/doc/refman/5.1/en/create-user.html
GRANT: http://dev.mysql.com/doc/refman/5.1/en/grant.html

This may be a job that phpMyAdmin can help with?

Related

Connecting a website to a database

I am sorry if this is the wrong stack exchange, if so please redirect me.
I am very much in doubt about how I go about the following, and I can't really seem to google my way to a solution, so here goes:
Let's say I have a website which basically only consists of a search bar, which I want to link up to a database which every user can search in. In addition to this I want to be the only one who can actually add new data to this database.
To do this, would I basically "just" buy a website domain, make some SQL query hookup to a database that I rent from fx Microsoft Azure? Then whenever people would search for a string the website would query the database and return any relevant information.
Is this the correct way to go about this issue?
For your scenario, I would suggest you use Azure App Service MySQL in-app, which has a cool feature for Web developers to create Web applications that use MySQL. You don’t need to provision a database explicitly as during the creation of the web app when using this feature.
For more details, please refer to Announcing MySQL in-app for Web Apps and Create a PHP web app in Azure.

Is it possible to send data to phpmyadmin from a windows/android application on a phone?

I am developing an application that needs to send data to a server so that the server data can be outputted on a website table.
My question is how is it done? I already know how to create tables and whatnot, but when a user creates an account on the phone application, how is it going to appear on the table on phpmyadmin?
# Zarathuztra convenient phpmyadmin is a tool to manage MySQL databases.
What you need is a script on the server that receives the requests from the smartphone is making special thinks inside. Save or manipulates the data in the database and sends the result back on to the phone. This is not the opinion, we can teach you on StackOverflow, sorry.
Watch out for cloud database services to your problem on the internet or ask are PHP-coder for help.

Outside database connection - (securely) - MySQL/PHP

I'm developing an online application that will have many outside users. As for now my connection method is to host a centralized database for all users, while they connect from their own server files.
Method:
PHP Connection File (hosted on their server; file provided by me) >> Connects to my MySQL Database
Now obviously I need to provide my database user and pw info, but I know that questions security.
So to my point, how would I provide database access to outside users(different servers) without giving up security.
Or if someone has a better method I'd love to hear it. Thanks!
Create an API in php, sort of webservice with an interface that you define and host this API on your server.
Each user (script that runs on users server and uses your API) needs a personal API key or access code they need to register to the webservice.
Take a look at well known API's like Google maps or something similar. Oh even stackoverflow has one
Create a signup form for users and store their own UserID and Password in a table on your site. Then create a PHP interface for them to upload their files. That way, you need only validate thier own UserID and Password through a HTML/PHP form to allow them to sign in, and your MySQL creds stay safely hidden.

How to handle user access to an application that can access multiple databases

I am considering a way of taking an existing php and mysql application that was developed for use in-house (and thus has a single database with nothing built in in terms of multi-tenancy).
I figured that it's possible and maybe in some way better to run each client of their own database. What I want to know is how best to handle the login of a user given the credentials supplied could be in any one of the databases and in some cases possibly multiple databases.
I had thought along the lines of iterating through each database and checking for valid credentials. If the credentials exist in multiples then return a list that the user chooses from, or if it exists only once then just logging in.
Is that a valid solution? Will it start to perform badly IF the application was to expand to have thousands of users across hundreds of databases?
I recommend installing a different instance of the app for each client, with their own database.
Each client should be given their own url to access the app, instead of having them all access in from 1 location, but pointing to multiple databases.
This will adress a few problems that you might encounter if you run all your clients from 1 location (multiple databases)
What happend if the different client has accounts with the same name? Which account will take precedence?
What happens if the client want to take over the app and host it seperately from the rest of the clients. How can you easily seperate out this client into a sepetare installation?
Another point to note, connecting and disconnecting to databases are expensive. If you have to do so 100 times when the user logs in to find out which database that user is in. It might bogg down the system or your database server.

PHP/MySQL export then import again

I build a small application using PHP/MySQL. After one year of development, I fell that I need to update MySQL tables structures.
I do that using (SELECT * INTO OUTFILE) it is work in my local server but not in any user that host his application in hosting company that use some thing like cPanel ( or Control Panel that given by host company to let user manage his web page, emails,ftp account, database...etc).
That type of hosting is not giving full root access to any user cuz it is share same hardware with many other clients.
edit:
I forget to tell you that I need to do that using php script I made, to let ppl run it on their servers to make this automatically. there is no thing to do by user..... this script will do the following:
1) get a copy for all data in each table.
2) delete/Drop all tables.
3) create new tables with new structure.
4) import data again to that new labels.
Use phpMyAdmin, available from cPanel.
if it's working on your local machine then it is highly likeable that the user you are using to connect to the DB does not has all the privileges required.
You can use cron jobs for regularly exporting (dumping) your databases. Also use phpmyadmin like JohnD mentioned

Categories