I'm facing this problem since yesterday evening. I have been now over 6 hours on Google, trying to figure out what the solution could be.
I have tried this, setting the timeout on all php.ini files to 300 or unlimited, I have tried setting the buffer of MySQL higher, tried to restart both Apache and MySQL server, ...
Problem: What I'm trying to do, where the error occurs, is to execute a SOAP-command (command is correct) $this -> soap -> executeCommand(new SoapParam($command, 'command'));, which results in:
"Could not connect to host" --> if I set define('DB_HOST', '127.0.0.1'); or
Problem 2:
//Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2003): Can't connect to MySQL server on 'blacktempel.dyndns-home.com' (10060) in C:\Users\NAME\Desktop\Server_09122014\Apache\_Server\htdocs\SOAPRegistration.php on line 109
//Warning: mysqli::close() [function.mysqli-close]: Couldn't fetch mysqli in C:\Users\NAME\Desktop\Server_09122014\Apache\_Server\htdocs\SOAPRegistration.php on line 154
$this -> db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); //Line 109
$this -> db -> close(); //Line 154
"Database connection failed: Can't connect to MySQL server on 'blacktempel.dyndns-home.com' (10060)" --> if I set define('DB_HOST', 'blacktempel.dyndns-home.com');.
My firewall is not the problem, I have checked this multiple times.
My hosts file contains this:
# 127.0.0.1 localhost
# ::1 localhost
MyExternalIp blacktempel.dyndns-home.com
SOAP:
define('SOAP_IP', '127.0.0.1');
define('SOAP_PORT', '7878');
MySQL is running on port 3306 and listening. My other defines, such as DB_USER, DB_PASS, are correct.
Q: Why won't it work ? What could be wrong ? Is there anything I could possibly have missed ?
Fixed the issue.
The SOAP problem was caused by a setting in the config file of the program accessed by SOAP.
Related
I have tested my MS SQL Server connection with this PHP code:
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'WIN-71KGFN2PPCC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'test1234');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}else{
}
?>
and had this warning and error message:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: WIN-71KGFN2PPCC\SQLEXPRESS in C:\inetpub\wwwroot\index.php on line 7
Something went wrong while connecting to MSSQL
I tried many solutions, I also enabled the TCP/IP protocol of my MS SQL Server from the SQL Configuration Manager, adding the port 1433 to it and to the firewall. Any other solution to it? Please help me.
I'm trying to run a PHP Script that contains a MySQL connection, when I run the command I get the following error in the terminal:
'Warning: mysqli::__construct(): (HY000/2002): Connection refused'
Even with PDO, I get the error:
'Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in ...'
I'm running the script on Mac OS X, and I have MAMP as APACHE/MySQL local server.
The command that I use for running the script is:
'php main.php'
and the content of the 'main.php' file with PDO is:
$db = new PDO('mysql:host=localhost;dbname=test',root,root);
with mysqli connector:
$db = new mysqli("localhost", "test", "root", "root");
I tried with '127.0.0.1' instead of 'localhost' and I get the same errors in both cases.
First of all, using localhost as a domain name is not supported in PHP. It will not be resolved as 127.0.0.1.
Second, even using 127.0.0.1 might not work in servers with multiple interfaces or with special routing rules. Run mysqlcheck --help and take the IP address shown at the bottom in the "host" field. For example:
port 3306
host 192.168.1.23
Use the IP and port that MySQL recognizes:
$db = new mysqli("192.168.1.23:3306", "test", "root", "root");
in mac i want to create cronjob but when i run the php file with database i am getting error in terminal.
Warning: mysqli_connect(): (HY000/1049): Unknown database
And In the browser run perfect.
check your port that mysql run .
in many cases mysql run in port 3306 but in my mysql it run in port 3308
and I add this:
$conn = new mysqli("localhost", "root", "", "myDB","3308");
I had a similar problem. My code was like this:
$conn=mysqli_connect($servername,$username,$password,$dB) or die("connection failed");
echo "connection success";
Problem: I did not indicate the port number.
Solution: I just included the port number, like below:
$conn=mysqli_connect($servername,$username,$password,$db,"3308") or die("connection failed");
echo "connection success";
Is your PHP environment the same as your browsers PHP? command line php.ini can differ from, for example, your XAMP or other installed webserver
I would recommend checking this first
for me this did the trick
edit your .bash_profile file like
export PATH=/Applications/MAMP/bin/php/php7.1.1/bin:$PATH
edit the path to your PHP bin from your XAMP
If you have this code:
$conn = new mysqli("localhost", "root", "", "myDB");
Try with creating new database called myDB in localhost/phpmyadmin.
In my case I got similar error
Warning: mysqli_connect(): (HY000/1049): Unknown database 'login.db' in D:\xampp\htdocs\login\functions\db.php on line 2
so i change [$con=mysqli_connect('localhost', 'root', '', 'login.db');] into
[$con=mysqli_connect('localhost', 'root', '', 'login');]
Ii changed 'login.db' to 'login' and error disappear
For me, the problem was the "Port number" (on Step 3 of OpenCart 3.0.3.2 installation) which was set as 3306 but in MySQL, it was showing as 3308 so I just changed the same and all went good.
enter image description here
When i try to connect to memcached server from a php page, it works without any problem.
Using this code
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
But when it tries to connect to server from a php script which is fired by cron job it throws this error
Warning: Memcache::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/...../cron/acts_cron.php on line 3
Warning: Memcache::connect(): Can't connect to localhost:11211, php_network_getaddresses: getaddrinfo failed: Name or service not known (0) in /home/...../cron/acts_cron.php on line 3
Could not connect
What can cause this problem ?
Seems like you're missing an entry for localhost inside your hosts file. Try updating /etc/hosts and make sure that you got a line like the following in there:
127.0.0.1 localhost.localdomain localhost
using 127.0.0.1 instead of localhost fixed the issue.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
I tried to connect mysql database.but am getting the following error.
Warning: mysql_connect(): [2002] No connection could be made because the target machine actively (trying to connect via tcp://localhost:3306) in test.php on line 5
Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in test.php on line 5 Warning: mysql_close() expects parameter 1 to be resource, boolean given in test.php on line 15
test.php:
<?php
$link = mysql_connect(localhost, dbuser, dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
This happened to us when running a PHP & MySQL on IIS7 in Windows Server 2008 in VirtualBox. It turns out that the Windows hosts file didn't have an IPv4 entry for localhost (127.0.0.1) so the route to MySQL on localhost was not found.
We added the following to the hosts file which resolved it:
127.0.0.1 localhost # Additional IPv4 entry
::1 localhost # Existing IPv6 localhost entry
Reference: A brief description of PHP/MySQL Localhost via IPv4 & IPv6
The MySQL server isn't running, or you have a firewall blocking port 3306.
This error message means the system did not accept the TCP connection request.
In my.ini find string:
bind-address = 127.0.0.1
Change from localhost to network IP.
Got the same message trying to connect to 'localhost' by mistake (on a Windows server). After fixing the connection string to the correct (remote) server the error disappeared.