I am working on php website for my class and I am having trouble connecting to my schools database server when i upload my files to my schools website. My school only has a database server on HediSQL and Workbench and I am currently using HeidiSQL to access the account database my school created for me.
I am currently using this code to try and connect.
$host='school.edu';
$user='user';
$pass='pass';
$db='db';
$port='3306';
mysqli_connect($host, $user, $pass, $db, $port);
Using this i can connect to my schools database just fine when i am on my own computer and run it through localhost, but as soon as i upload my website using SSH to my schools server, the website cannot connect to the database.
Any help would be appreciated! Thank you.
Edit: I am using php, heidiSQL, and SSH secure file transfer.
$host='localhost';
$user='user';
$pass='pass';
$db='db';
$port='3306';
mysqli_connect($host, $user, $pass, $db, $port);
Please make changes to the $host variable.
$host = 'localhost';
host is always use as localhost on server
Related
Hope everything is fine.
I have a yii application, there is a connect.php file that will allow me to connect to the database.
$host= 'localhost';
$conresult= #mysql_connect($host, $mainuser, $pass);
//echo $db;
$result = mysql_select_db($db, $conresult);
if(!$result){
//echo "no";
}
We have moved the database server to the internal network for security reasons.
When I change the host from localhost to the new IP address, the website hangs.
The port is open and the security network saying that the connection is established.
How can I remotely connect to mysql server database in yii.
Thanks.
I recently set up RDS server using MySQL dataset and using EC2 beanstalk as a server.
I have been able to connect to dataset from
console of local machine using endpoint url, username, password
from PHP on local machine, using following code:
$servername = "xxxxx.xxxxxxxxxxxxxx.us-east-1.rds.amazonaws.com";
$username = "xxxxx";
$password = "xxxxxxx";
$dbname = "xxxxxxx";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname, 3306);
// Check connection
if (! $conn) {
echo "not connecting..!!";
die("Connection failed: " . mysqli_error($conn));
}
This works correctly, inserts data into the database in the RDS.
I ssh to EC2, check connect from console (using mysql -h -u -p). This too, work correctly. I can change the database from here and it is indeed reflected.
Next, I deploy the exact same code on EC2, and hope it works via PHP as well, as that code is already tested. But it does not.
I checked SELinux status is disabled
What else could be a problem?
I should mention: I am using Amazon Linux, I installed 'httpd' on local it.
When I am installing XAMPP I have not installed MySQL where I have already using this database so I have not installed using xampp but in my PHP code when I am establishing connection I wrote
$conn = mysqli_connect($servername, $username, $password, $dbname);
At $servername, everyone is keeping localhost and explaining PHPMyAdmin examples where MySQL is installed in xampp
In my case MySQL is at c:/programfiles/MySQL what I have to give at my $servername
Please help me, I am new to programming
localhost isn't the name of your MySQL server's install directory. It's a reference to your local machine aka 127.0.0.1. Your server name is still localhost.
The only time you'll change this is if you host the database on a different machine.
I created a working web app with login/register etc using a local dev server/wamp on my laptop, but require to move it all to linux server on a different system. I recreated the database identically in phpMyadmin and i am using the following connection string:
<?php
$server = '150.204.20.22';
$user = 'enramclo';
$pass = '***';
$dbname = 'enramclo';
$dbcon = mysqli_connect($server, $user, $pass, $dbname)or die("Can not connect to Server.");
?>
All these details are correct, but it simply will now not connect. I have little experienc eof linux so is there something I need to know as to why it will not work?
What is the os type? You might have SELinux enabled. Try to execute in shell and see if it's works
setenforce Permissive
I want to ask about how to connect my localhost application (C:xampp/htdocs/myproject) to database at my server host (www.someweb.somedomain)?
Am I possible to do that? If it is, how to connect it at my php config? Right now my config (server.php) is:
<?php
$host = "my web IP public:3306";
$user = "root";
$pass = "";
$db = "dispatcherDB";
$conn = mysql_connect($host, $user, $pass) or die ("Cant connect to mySQL");
mysql_select_db($db);
?>
what I got:
Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\XMS\server.php on line 7
So, what must I filled for $host? I'm trying using website IP, it still can't connect. Maybe there's someone here have experience at this problem?
Sorry for my bad English
If you have cPanel access to the remote server then you need to mention that from which ip addresses it should allow access to MySQL..
In cPanel you will get Remote MySQL under heading Databases:
Clicking Remote MySQL will give you the option to add hosts from where you want to allow connections to your MySQL server:
Also, you can check localhost without specifying port number as value of $host..
Probably Mysql server is not allowed root access from remote servers.
you could check this post