Accessing remote SQL Server database - php

I'm trying to access the mssql database of my website which a web design team has designed. They have given me the ip, port, db name, user and password... but how can I connect to the mssql server?
I have tried doing it via php but I think I have to compile php without "--without-mssql" "--without-pdo-mssql"... which I would not rather do on this windows 7 computer unless I have to.
I've tried SQL Server Management Studio Express but I couldn't find a way to access to a REMOTE database.
I've also tried Razor SQL but that did not connect either.
I almost tried something like phpmyadmin for asp.net but wanted to find an easier solution for this- without installing asp.net.
So what would be a good solution for managing a remote mssql database? Is there a program like Office Access that can handle such job?

SQL Server Management studio does support remote connections, in the small dialog you see in the middle of the screen when you run it, specify IP, username and password.
do you get any error? Which error do you get?

I am a fan of Navicat:
http://www.navicat.com/en/products/navicat_sqlserver/sqlserver_detail_win.html
However, I have not used the Sql Server version, but the MySQL and Oracle versions are pretty good - MySQL is awesome (mid range price point is the only draw back).
However Navicat Lite, which is still pretty good (and can handle most server types) is free!
Just a note, has the remote DB been setup for remote connections? If not you will not be able to get access no matter what you use.

Related

What to do about MS Access in PHP in Unix?

I need to pull data from MS Access 2007 (both mdb and accdb files) for a website written in PHP 7. The pages don't need to be dynamic or interactive. They just need to present data stored in the database.
Local development environment: Windows 7, IIS 7.5
Online server: A2 Hosting, Linux (CloudLinux Server release 6.9), Apache/2.2.34
The ADOdb webpage for Access says "Windows Yes, Unix No". I presume this means I can use ADOdb to connect to Access in my local environment, but not on the online server. I suppose I have the following options:
StackOverflow has some questions on this (1, 2, 3) with answers that give code for connecting to Access in PHP. Although the answers don't say so, I am guessing that that code will only work in Windows because if it were that easy to connect to Access in PHP in Unix, then ADOdb would do it! So if I'm right about this, then this is not a workable option.
The PHP Manual has a page on Database issues that says PHP can access Access, but it seems to only apply to either running in Windows or "running PHP on a Unix box and want to talk to MS Access on a Windows box". So this also does not appear to offer a workable solution for running the website online on a Linux server.
Extract the parts of the database needed into something else that can be accessed in Unix, such as CSV files, and use that as the database for the website. If I do this with CSV, I suppose I don't need ADOdb, but would just use fgetcsv(). This is an inelegant solution, but may be the best thing to do if there's not a way to access Access directly in Unix. (I could use MySQL instead of CSV, but that seems like a lot of unnecessary overhead.)
Run the pages on my Windows machine using ADOdb to access Access. Save the parts of the pages that come from the database as separate HTML segment files and include() them when the pages run online. (The script could detect which environment it's running in and if it's local, then access the database, and if online, then include() the HTML segment files.)
Move the online website from Linux to a Windows server, so PHP can access Access directly using ADOdb.
Convert the entire database from Access to something else, such as MySQL. This is not practical at this time, although that may be an option in the future.
Have I understood my options correctly? I've listed them in what seems to me to be the order of preference, so unless someone suggests otherwise, I guess I'll go with the third one (extract to CSV, use fgetcsv(), no ADOdb) since the first two won't work.
Thanks for your help.
The main problem is the ODBC driver. The {Microsoft Access Driver (*.mdb, *.accdb)} comes with Microsoft Access or the Microsoft Access Database Engine, which are both Windows-only.
However, there are alternate ODBC drivers that work on Unix and unixODBC. A popular open source one is mdbtools, which is limited, but can be used to connect Access to PHP on unix using PDO and ODBC. There are also commercial alternatives that are more fully featured.
Once you've got that working, it shouldn't be a problem to use the ODBC driver in PHP. Note that on shared hosting, this might not be possible.
Alternatively, you can use a php-jdbc bridge with UCanAccess. This might still be all-open-source and more fully-featured than mdbtools, but is more complex to set up correctly.
You don't need to convert "the entire database" from Access to use Mysql, just the tables. You can then link them back into the Access database using the MySql odbc connector and so long as the table names are the same you won't even notice the difference, all your forms, queries and everything will work.
You would then have MySql server running on your local machine which, if you create a user with the right permissions and port forward through your router (directing traffic from port 3306 or whichever port you assign to your server, to your machine) and allow the traffic through your firewall, your website can then access, read and write to your database.
If you want to query the database from php mysqli_query will work just fine. Most websites that run from data run using MySql, so this is a future proof solution too.

How to set up a website with a PostgreSQL database?

I'm doing a group project and we're creating an online game. We're about half way done and now it's time to implement a database to store our records/data and make the website go live on the internet.
I'm just confused on how PSQL works exactly. My understanding is that PSQL needs to be running on some server in order to access it. For previous assignments, I downloaded Postgres for my Mac and ran it on localhost. The PHP code was something along the lines of:
$dbconn = pg_connect("host=localhost port=5432 dbname=mydbname");
So, if we intend to use PSQL, where would the server be? Do one of us have to host the server? Can we use some sort of free online server? How do we connect to that server with PHP?
In summary, I have two main questions:
How do we make our code go live on the internet for free? (It's just a temporary website and will only be up for a few weeks at most)
How can we all access a shared PSQL database?
Sorry for the noob questions, I just got started with web development and am still learning.
So, if we intend to use PSQL, where would the server be? Do one of us have to host the server? Can we use some sort of free online server? How do we connect to that server with PHP?
PostGreSQL is going to have to run on some machine visible to anyone who needs to access it. If only your web server (i.e., the machine running PHP and your website) needs to talk to the PGSQL, then PGSQL can be installed on your web server. This is a very common configuration.
The server might also run on the LAN where your web server is running or it might be running on an entirely different network on a different continent. The most important thing is that any machine which must connect directly to the database can actually connect to it. If you're building a website, this means you have a web server. Your web server will need to connect to the PGSQL server. The second most important thing is that your web server and the PGSQL server should share a very fast connection for the sake of performance and efficiency.
It's probably most common for your web server to also host the database. On an ubuntu machine, installing a PostGreSQL server is as easy as running a few commands. A quick search yields many examples like this one.
How do we make our code go live on the internet for free? (It's just a temporary website and will only be up for a few weeks at most)
I don't know anyone who is in the habit of offering free web hosting or DBMS services. You could ask a friend. Or put an ad on craigslist or something. Or if you are tech-savvy (it doesn't sound like you are) then you could configure a high-end router at your home to use Dynamic DNS to point some domain at a machine running at your house.
How can we all access a shared PSQL database?
I have no experience with Heroku, but you might sniff around there. PostGreSQL's website also maintains a list of hosting companies. Amazon offers RDS instances running PGSQL. Digital Ocean has a variety of tutorials and how-tos on dealing with PostGres. You could probably fire up a 'droplet' server for super cheap and install it yourself without too much effort.
Amazon offer a free tier database solution for Postgres. Something like 300 hours (don't quote me on it) for a low level set up.
They have tutorials on doing this here:
https://aws.amazon.com/rds/?nc2=h_m1
Once set up you get the end point and your connection string becomes something like
db_connect ("host=[URLENDPOING] user=postgres dbname=postres")

How to send data updates to a hosted MySQL database remotely over the internet?

I have a simple MySQL database (one table with 12 rows of data and 5 columns) sitting on the web-server of my host provider.
On my home PC I create the data programmatically and store it in a free version of SQL Server (on my home PC). I would like to "upload" this data to the MySQL db in real time (or as close as I can get) over the internet (I'm assuming this is the only way to connect the pipes).
I know that opening up a MySQL database to a remote internet connection probably is not a "secure" thing to do, but the resulting data table will be publicly available anyway via an "app" so I'm not too worried about that (I suppose a hacker could "overwrite" my data with their own if they were both industrious and inclined) but I think the risk/reward is so small its not a major concern.
Anyway, what is the easiest way to do this with some semblance of security? I only know how to program in VB (I did a little HTML and ASP back in the day, but that was a long time ago). I could learn a few lines of code in another language if need be.
I do not have a static IP, and I've never actually interacted with a MySQL database before (only SQL server, so my MySQL knowledge/ familiarity is zero...but a db is a db, so how hard can it be?). Because of my home network firewall, I can't allow connections "in". I will have to make the connection to the MySQL db "out" from my home PC --> to the hosted database.
Ok this problem is not actually super simple.
What you will find is most shared hosting providers do not allow just any IP to access their databases.
Solution? set the IP for your computer of course! BUT.....you are probably on home internet connection so your IP address can CHANGE (if you have a static IP you are a lucky person!)
So the best way - create a mini-API!
Basically, you want to post your data to a script (with some security of course) that then inserts this data into the database.
It is a lot of work but having done all this before it seems to be the only way unless you have a dedicated server / advanced access privileges!
You could take a look at WAMP for your home pc. It's simple to use.
And then you should take a look at Mysql remote connections(some details here)
I would try this:
At your local computer install MySQL server, there's a free community
edition available for download, try the web installer since its more lightweight. Use the
custom installation and make sure MySql Workbench is selected too.
Workbench has a migration tool for the most common databases, Try this locally, so you can tell if all your data is correctly migrated from your local SQL Server to a MySQL db and there are no data losses in the process.
Then, You could probably connect through Workbench to your online MySQL db
and migrate your data to it directly from your just created local db. In case you cannot connect, make a backup of your local db and send the files to
your server by ftp or similar process. Then, simply restore DB from the backup file on your
online server.
Hope this helps!

'Mirror' database connection using PHP

Now before I start I just want to say that I have absolutely no idea if this is possible.
The Question
I am used to managing databases on my computer using Sequel Pro, and that is what I have done for the past few years with my Linode VPS. I recently purchased iPage hosting to store some static content and I wanted to set up a database to keep an easy archive of it. Having created the database and set up the access details I wrote a basic PHP script for it.
I wanted to connect via Sequel Pro, but with a lot of shared hosting they don't seem to let you do this for security reasons. My question is, would it be possible to write a script that you connected to the same way as a database, but which processed all your requests to the database before returning it? If it is possible, how would you go about it, and if it's not, why?
SQLyog has php proxy, and it is generally one of the methods for connecting to mysql databases which are bound to localhost. Also, some cPanel hostings have an option where you can specify external IP which can connect to the database, have you asked the support if there is such an options?
In SQLyog, feature where they use php proxy is called HTTP Tunnel. Maybe there exists something like that for Sequel ?
https://static.webyog.com/docs/SQLyog/HTTP_Tunneling_SQLyog_MySQL_Client.html

Adobe AIR with PHP/MySql or SQLite

What would be a better choice for making a database driven
Adobe AIR(Desktop) application?
Using PHP+MySql with AIR
OR
Using SQLite
If I choose SQLite, then I cannot reuse my code for
an online application.
If I choose 1, I have to block few port numbers on User's machine.
Also, I am using XAMPP for providing the user with PHP and MySql, so
XAMPP opens up a command window as long as it's running. And, users
get confused about what's that window for? It makes the end user
experience slightly confusing.
I'd definitely use SQLite as its included in Air.
May I suggest; write your code in two sections. The UI which uses a JSON feed to populate itself, and the API to provide the JSON data. When it comes to port the application to the web you can use the same UI but with a rewritten API.
Whatever you do, don't open up a command window while the program is running. If you do that, your customers will uninstall like there's no tomorrow.
As far as mysql vs sqlite, the standard approach is - if it communicates remotely, feel free to use mysql, but if you're installing the db on the client, you should use an embedded standalone db (sqlite).
How complex do you expect your app to be that you can't use sqlite (besides not being able to reuse some of the code that you mentioned)?
If XAMPP is too confusing for your client, install Apache and MySQL as standalones. It's essentially the same thing and you'll have more control over what's running in Apache/MySQL. Plus you won't get an annoying command window (though, to be quite honest, I don't recall a window that I couldn't minimize to the tray when I ran XAMMP).
My suggestion is use Sqllite as your local database and writes a synchronization API that will synchronize the local sqllite database with the server side database-MySql. So according to your client you can use the system. If the client is standalone then Sqllite will serve otherwise the MySql will serve. Only thing you have to decide in both this is how to use the synchronization api.
Just check the Sample Application

Categories