C
C
ChemAli2013-04-05 11:45:15
PHP
ChemAli, 2013-04-05 11:45:15

PHP script can't connect to MySQL when running from console and web server with the same settings?

The connection string looks like this:

$mysqli = new mysqli('localhost:3306', "user", "pass", "db");

This works when run from the command line (php script.php) and the connection is normal. But it doesn't work when run through a web server ( localhost/script.php). At random, it turned out that if you remove the port, then it starts working on the web server, but it cannot work in the terminal at the same time:
$mysqli = new mysqli('localhost', "user", "pass", "db");

How to treat?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
ChemAli, 2013-04-05
@ChemAli

I'm a moron: these are different php being launched, which is why, apparently, the fakap.

L
LastDragon, 2013-04-05
@LastDragon

Have you tried using localhost IP instead?

A
Anton Kuzmichev, 2013-04-05
@Assargin

No, guys, that's not going to work. We don’t even bother to look at the documentation before writing such questions.
Are you used to what is indicated everywhere in the form of host: port? Nope.

$mysqli = new mysqli('localhost', "user", "pass", "db", 3306);

And localhosts have nothing to do with it. And don't ask why "it worked at least on console/webserver"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question