Okay, I know this may be a very noobish question, so forgive me, but right now I have XAMPP and I'm running a local Apache server on my personal computer to test PHP code. I have setup a test database through phpmyadmin on a webhost (Hostgator), but it's looking like if I want to connect to that database I need to have the PHP file that I am editing on the same server because any of the tutorials I read tell me to use locoalhost for the servername requirement when using MySQLi or PDO.
Is this because you 'can't' connect to a database on a separate server? Or because it's just not common because there is a better way to do things? (I've seen hints on being able to download MySQL and phpmyadmin onto my PC, and then importing and exporting tables, but what I've seen hasn't been clear on if that's what I need to do for this or not.)
Thank you!
No, it's very common practice to use different machines for web and mysql. There could be a few issues (not familiar with Hostgator but I've dealt with similiar). One is likely firewall. Anything external to the Hostgator network will not have access.
if I want to connect to that database I need to have the PHP file that
I am editing on the same server because any of the tutorials I read
tell me to use locoalhost for the servername requirement when using
MySQLi or PDO.
I'd find better tutorials. It's good practice to separate your MySQL Server away from your web server.
It is possible to connect to a database server running on another machine provided that the server machine has the appropriate ports open in its firewall and that there is a route between both machines.
Problem solved! I had to go into the Remote MySQL and allow the IP address. Again, maybe a noobish thing, but I had no idea that was something you needed to do. Learned from this though! Thank you everyone!
You can do it, and I see that you figured it out.
However exposing your database to the public internet is never a good idea, so for security purposes it is turned off by default.
If the reason is just for testing your code then it is better to setup your development environment with a local mysql server, this way you don't mess with production database.
Related
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")
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
I am quite new in PHP and databases. I am trying to connect to a remote Postgres database from my computer. In the past I have done this by using a localhost and a MySQL database but it is the first time that I try to connect in another host.
This is the PHP code that I have:
<?php
$conn_string = "host=hostname.com port=xxxx dbname=dbname user=root password=root";
$dbconn = pg_connect($conn_string);
?>
I read several articles in internet saying that it is enough to change the hostname from localhost to the one provided but it doesn't seem to work. I also have deactivated my firewall in case there is some problem with the communication but with no success.
As I said I am quite new with this and in the past I had used only test servers (localhost). Back then I was using software like Wamp and Mamp and I was placing the script files in the localhost.
So, my questions are:
1) where should I save the test.php file which has the above lines of code?
2) Would this solve the problem or I am missing some important concept here?
I hope what I am trying to say is clear. Please let me know if I have to be more specific in something.
Thanks
Dimtiris
First, error messages would really help. Based on the comments I will say I suspect that you are connecting to the right server. However you are using a username of "root?" It would be highly unusual for such a username to be present on Postgres.
The first one is where to put the file. This should be put in your web server's document root or cgi bin depending on how you have things configured (probably the former).
For your second question, please double check usernames and passwords, and make sure you can use those usernames and passwords via pgAdmin III to connect to the same db. Making sure you have the credentials right to start will make your code a lot easier to troubleshoot if things don't go right.
I'm using a self-made customer system in PHP running with a local mySQL Database.
Now i have a second computer on a different location which has to use this Database too. So i gave this mysql Database on a Server reachable through internet.
My problem is now, that the first one has often problems with the internet connection and then the program will not work. But it has to work every time!
Now i do not know how i should handle this problem?
A local Database and one in the internet, but how should i merge them?
Should i make a local DB per computer and match them together in one?
I also want to change the framework behind this system to symfony2 so is there a way to solve this problem with this framework (e.g. doctrine?)
Thanks for your help!
Update:
My limitation is the Internet connection on the first computer which could not be eliminated.
If you really have limitations of (1) not being able to move the database off of the machine with a bad connection and (2) not being able to fix the bad connection; you are going to have to keep some sort of local instance on the second machine.
I would try to setup master-master replication from the first machine with the bad connection to the second machine. I'm not sure how reliable this will be considering the replication will be failing often due to the first machine's bad connection. This problem may be extrapolated if one or both machines are using old versions of MySQL. MySQL 5.5, for example, can be configured to actively monitor replication connectivity.
If the majority of your application does READS instead of WRITES, perhaps you could install Memcached (or something similar) on the second machine so that the application can pull data from local memory without requiring a connection to the MySQL server.
There are a few ways to achieve what you want (although maybe not exactly how you described), but the best way is definitely do host the database on a server that doesn't have Internet connectivity problems. Look for hosting that allows remote MySQL connections.
I have a standard php app that uses SQL Server as the back-end database. There is a serious delay in response for each page I access. This is my development server, so its not an issue with the live setup, but it is really annoying for working on the system.
I have a 5 - 8 second delay on each page.
I am running SqlServer 2000 Developer Edition on a Virtual Machine (Virtual PC).
I have installed SqlServer on my development machine but get the same delay.
I have isolated the issue to the call to mssql_connect (calling mssql_pconnect has no effect)
It is a networking issue on how I have set up (or not set up, since I didn't really change default config) SQL server. It's not a strictly a programming issue but I thought I might get some valuable feedback here.
Can anyone tell me if there is a trick, specific set of protocols, registry setting, something that will kill this delay?
I was also experiencing a 5-10 second delay on every connect, using the official Microsoft SQL drivers for PHP (as suggested by #gaRex) - none of the answers posted here solved it for me.
As suggested by #ircmaxell, my problem was a DNS issue - and the solution was to edit the \windows\system32\drivers\etc\hosts file (your local local host file) and add the name of my own machine to it.
In the "system properties" dialog, find the "computer name" of your machine - then add a line like 127.0.0.1 my-computer to your local host file.
For me, the delay occurred once more, on the following attempt to load the page - after that, it was super fast, no delay at all.
Note that this problem may occur even on a physical machine, not only on a VM.
I came across network issues when running virtual pc, everything network related is slow, try adding this entry on your registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Create new DWORD value named DisableTaskOffload and set its value to 1.
Restart the computer.
It worked for me, source.
Is it perhaps a DNS issue? I know that MySQL does a reverse DNS lookup on each login (not each connection). If you don't have a reverse dns record for your server (or your dns is slow) it can cause a major delay at login. There's an option in MySQL to disable that. I'm not sure about SQL Server, but I'd assume it may be doing something similar...
I remember the same problem, but forgot, how we have solve it.
To clarify please specify exact connect strings, your SQLserver versions and also try to start this old good utility c:\WINDOWS\system32\cliconfg.exe, which is also can bring some light.
Yes, I know, it's from 2k, but guys at m$ don't like to create client tools from scratch.
Also try to get "right" mssql client dlls for PHP.