Really can't figure out how to word what I need...
I work with a site through SCP. And sometimes it crashes due to the database server fault. But actually I don't connect to that database. So I need to see all possible connections that my site can use. I found two files at include path that contain connection to server that faults, but my files don't include them. If I can give some more info please ask me.
All connections are made through odbc_connect("DSN_NAME;host_address", $login, $pass)
How did you find out that your SCP crashes because of database server fault? It shouldn't. I think the problem is not in database. By the way, MySQL allows to configure many connections, so I believe the problem is in something else.
$con=mysqli_connect("example.com","peter","abc123","my_db");
Related
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.
I have defined my database connectivity in database.php. I have 4-5 connections. Some are remote IP's. Problem occours when some IP goes down, i can access my application. Is there a work around for this i.e. application should work even if some IP connectivity is not there.
If you are using PDO, put inside a try.
If you are using mysql_connect use an IF to check the connection
This is just a quick question, I couldn't find it on the internet, but I did wanted to have a confirmation.
Say that if I, using PHP, want to connect to (for both the same) MySQL server, but I want to use two databases, not tables. Because you can connect to only one MySQL-database in the PHP mysqli_connect() command, will, connecting to two databases, though on the same server, use two connections.
Because then it'll probably go fast with the max_connections, right?
P.S. What was the SQL-command again to see the mac_connections value again? I thought it started with GET GLOBAL ... or something, but I might be wrong.
I do not have access to the server, only to (limited) FTP files (it's a bit irritating).
SHOW VARIABLES LIKE '%max_connections%'
If you have both databases in same server you can connect to the server and select one database. You can query from any other databases in the server as long as you have permission. Use the syntax databasename.tablename.columnname in your queries.
If your databases are in different server you may have to do little more work on the server side. you can use the The FEDERATED Storage Engine
I already found it, though I ran into it by pure accident mysqli_select_db().
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 have to code an application on my server that triggers emails based on info that come from a database hosted on another server and I don't know how to query that information. I'm using PHP/MySQL. I can't established a connection to this database like I do normally (when database is host on the same server that the application file), right?
Thanks in advance,
Wrong, there is no difference whether code and database are on the same or different servers. As long as the remote db server is configured to allow conections from foreign hosts that is... But that's a hosting issue not a programming one.
I'm not really sure why you wouldn't be able to. I've hosted databases on servers other than my hosting server before.
Try this
$my_db = mysql_connect('yourdb.com:3307', 'myuser', 'mypassword');
if (!$my_db) die('This might be a problem: ' . mysql_error());
If mysql is on another machine , from mysql, you have to give permission for outsider.