Deploying a small PHP + MySQL service - php

I am deploying a small PHP + MySQL service to my client and would like to know what is the proper way to set up the database:
Should I use the hosting provider control panel and create the database schema?
Or should I put SQL CREATE scripts in my PHP to run during the "init phase"? Do hosting providers even allow PHP to create tables?
It's a really small site, one tiny info page and one web service page for fetching data from the database.

I usually offload all deployment tasks into an install script. This way you can deploy in a matter of seconds, and can repeat if necessary. I do not know of a way to restrict scripts from database modifications (other than mysql user permissions, which will typically be defined by you)

It may depend what your hosting provider offers - personally I would use the control panel which should at least provide phpMyAdmin. You can then export your schema from your development database and import it to the live version.

Depending on your hosting provider you get a number of databases. Worst is 1 database, with a fixed name, most do 5 or more, with the ability to create your own database name. Often with a prefix.
I would go for the panel from the hoster, all though you can give any SQL statement through PHP.

Why add the complication of PHP for the installation?
Just use raw SQL. Simpler. Fire that into the database.
Use PHP for the interface. Creating tables/stored procedures/triggers etc is a one off event.

Related

Provide simple mysql table administration interface in a hosting environment

I have a web portal, consisting of various projects, based on MySQL database. The project administrators need to administrate their tables. I would like to provide them some already existing, free, simple interface with as cheap setup as possible (like 10-15 minutes max of my time per each new project - IMPORTANT! The number of project administrators and their requests grows...). It should support:
required: table export, import, insert new row, modify existing rows
not needed, but a plus: foreign keys replaced with some other field value from the foreign table (usualy a "dictionary"), display only certain columns, etc.
The problem is that it is a hosting environment, so I have no superuser permissions to the MySQL database. I don't have the grant permission so I must ask my hosting provider to run every grant command, so I want to minimize these requests as it is an above-standard service (it's their grace to me). And these requests would have to be done quite often.
What database administration tools/solutions can I use?
My ideas:
1) MySQL ODBC connector + MS Access as a client. The MS Access would connect via ODBC connector to the MySQL server. I can prepare small MS Access file that would contain a link to desired tables, and also quickly generated forms!
This is cool, however, I would need to contact my provider every time to create db user with desired permissions... to prevent users from changing table structure or destroying other tables...
2) Client -> Proxy -> MySQL server. Like in 1), but with some proxy. I'm now theorizing, but the Access could also use other protocol (e.g. HTTP) to connect some proxy that would handle the permissions and this proxy would then pass it to MySQL server. Does there exist something like that?
3) PHPMyADMIN. The problem from point 1) remains. However, the permission checking could be theoretically implemented on the PHP level here, so no need to change any MySQL permissions! Is PHPMyADMIN capable of that, out of the box? Can I simply configure a new user which can only see table A & B and only modify column C, etc.?
However, the import is not much user friendly (no XLS, only CSV, no delimiter autodetection etc.), as well as inserting new records...
4) There are plenty of modern web tools with spreadsheet-like look like GoogleDocs. Could these be used for the task. Again, in theory the permission checking could be done at the web-server (not database) layer... and set up easily... (?)
I'm sure many people had to solve the same issue, so I'm looking forward your experiences and ideas!
My final solution was a deal with a hosting provider - I asked him to create 5 dummy database users for future usage and also asked him to grant me the GRANT OPTION privilege. So I can configure privileges of those users, without having to ask the hosting provider! I did'n know of this possibility at the time of asking.
And then, I use MS Access with MySQL ODBC Connector as a front-end to the MySQL database. Great1!

Python sync with mySQL for local application?

There have been many questions along these lines but I'm struggling to apply them to my scenario. Any help would be be greatly appreciated!
We currently have a functioning mySQL database hosted on a website, data is entered from a website and via PHP it is put into the database.
At the same time we want to now create a python application that works offline. It should carry out all the same functions as the web version and run totally locally, this means it needs a copy of the entire database to run locally and when changes are made to such local database they are synced next time there is an internet connection available.
First off I have no idea what the best method would be to run such a database offline. I was considering just setting up a localhost, however this needs to be distributable to many machines. Hence setting up a localhost via an installer of some sort may be impractical no?
Secondly synchronization? Not a clue on how to go about this!
Any help would be very very very appreciated.
Thank you!
For binding Python to MySql you could use HTSQL:
http://htsql.org
You can then also query your MySQL DB via http requests, either from AJAX calls or server-side e.g. cURL (and of course still have the option of writing standard SQL queries).
There is a JQuery plugin called HTRAF that handles the client side AJAX calls to the HTSQL server.
The HTSQL server runs on localhost as well.
What OS would you be using?
How high-performance does your local application need to be? Also, how reliable is the locally available internet connection? If you don't need extremely high performance, why not just leave the data in the remote MySQL server?
If you're sure you need access to local data I'd look at MySQL's built-in replication for synchronization. It's really simple to setup/use and you could use it to maintain a local read-only copy of the remote database for quick data access. You'd simply build into your application the ability to perform write queries on the remote server and do read queries against the local DB. The lag time between the two servers is generally very low ... like on the order of milliseconds ... but you do still have to contend with network congestion preventing a local slave database from being perfectly in-sync with the master instantaneously.
As for the python side of things, google mysql-python because you'll need a python mysql binding to work with a MySQL database. Finally, I'd highly recommend SQLalchemy as an ORM with python because it'll make your life a heck of a lot easier.
I would say an ideal solution, however, would be to set up a remote REST API web service and use that in place of directly accessing the database. Of course, you may not have the in-house capabilities, the time or the inclination to do that ... which is also okay :)
Are you planning to run mysql on your local python offline apps ? I would suggest something like sqlite. As for keeping things in sync, it also depends on the type of data that needs to be synchronized. One question that needs to be answered:
Are the data generated by these python apps something that is opague ? If yes (i.e. it doesn't have any relations to other entities), then you can queue the data locally and push it up to the centrally hosted website.

Move data between databases on two shared hosting accounts

I have two shared hosting accounts, each with a database of its own (its own cPanel login). Assuming these two databases have the same structure, what do I need to do in order to synchronize them?
The synchronization script would be on a domain connected with one of the hosting accounts. I know the MySQL/PHP for synchronizing databases that are on the same account is fairly simple, but what's confusing me here is how to access the database which is on different hosting?
This isn't a one-time thing, I need to be able to do this by clicking a button/link.
The only thing that comes to mind is having the remote database export everything to .csv files on a regular basis and have the script on the domain connected to the first database import everything, but there's gotta be a better way?
In case this whole question is confusing, the gist of the problem is - is there a way to have a script on a domain access a database on a completely different shared hosting account?
In short, no, there's no way.
Usually, hosting providers allow DB access only to localhost users. Meaning that script from another machine can't access it.
Also, what kind of synchronization is it? One-way or two-way? (but, I guess, this is out of scope here)
The only viable solution that comes to mind is some kind of dump/restore procedure.
Example:
webserver A (source of data) defines an URL, by requesting which you can get dumped content of the DB
webserver B (destination of data) defines a page with button 'Sync'.
upon clicking the 'Sync' button, server B will fetch that URL from server A, receive A's data and merge it with its own.
NOTE
It is important to secure data export URL. In that script you can check, for example, IP of incoming request, or presence and correctness of "access_token" or whatever you like.
Can you connect to the database via the SSL/SSH or PHP tunnel? If so, try Data Comparison tool in dbForge Studio MySQL.
Data Comparison tool will allow you to compare data between different databases. You may test it with a trial version.

MySQL table replicated between servers

Thats the problem I'm facing:
Given tree servers, each one offers some web services and have a table login like:
[id,username, password, email,...]
My target is to allow the access in each server to the users in the others, keeping the inter-server independence The desired behavior isn't complex:
When a user is registered in one of the servers that user should be added to the other servers without taking too long.
When a user change his pass in one server the others server must reflect that change too.
If two changes collide then keep only the newest change
I have been asked to do this without spending much time so I wonder if there is any standard and easy-to-perform solution to this problem.
All the servers use REST web service with PHP and MySQL.
It is for a shared hosting so I can't perform admin actions like configuring the mySQL server
You can replicate data between databases using MYSQL replication.
Usually it is used to replicate a whole DB but you can use do/ignore and rewrite rules to specify which tables to replicate.
replication filtering rules
replication logging
I have never used MYSQL replication this way so can't help further than this but I know it is possible.
You can create two mysql users.
first user will given write privileges and point to master
second user will given read only privileges, can load balance between the three servers
Change your application when require write, connect mysql using first user.
If require read only, use the second user.
I don't think share hosting is an problem,
pay more money to ask the hosting company to do the necessary configuration (that's obvious)
Or seek for other hosting company that allow administrator access such as AWS.

Bring data periodically from Linked Database in SQLServer 2008

We are developing a system on PHP with SQL Server 2008. Is a system that must work with the invoices stored in another SQL Server instance, that I have linked to my Database using sp_addlinkedserver.
The problem is that I think I need to have it loaded locally (because of performance). Si I'm thinking to make a my own "invoices" table, and two times per day somehow bring the data from the linked table to the locally stored one.
How can I program SQL to do this every X amount of time?
What approach I should use to program the importing?
It first I though to make my own script to do this, but I would preffer to have SQL Server to handle this, but that depends on your opinion :)
Thnak you!
Guillermo
NOTE: Replication sounds overkill for me.. I dont need to have real-time synconization. Neither I need to update the database, just read.
One option is to use replication to copy the data. However, it may take more administration than you're planning. Replication is great for managing a consistent and timely copy of the data.
Another option is to setup a SQL Server job that will run a SQL script to insert into your target table using a select from your linked server.
You could also use SQL Server Integration Services (SSIS). You would create a SSIS package where you would build a data flow that transfers your data from the source table to the target table. You wouldn't need a linked server for this approach, because your data sources are defined within the SSIS package. And, you can use a SQL Server job to schedule the package run times.

Categories