Query MySQL in PHP only works locally

5

It's as follows: the system I'm servicing was using two query types (do not ask me why) and locally (localhost) work perfectly. When I uploaded the project to the server, the queries declared like this:

<?php $sql = mysql_query("INSERT INTO entrada_produto (id_produto, descricao, qtde, valor_unitario, unidade, cd, data_entrada) VALUES ('{$id_produto}', '{$descricao}', '{$qtde}', '{$valor_unitario}', '{$unidade}', '{$cd}', now())") or die(); ?>

They do not work. They display the following error:

Warning: mysql_query() [function.mysql-query]: Access denied for user.........
    
asked by anonymous 11.02.2014 / 18:21

2 answers

9

For security, many default installations and web hosts configure the default MySQL user to be usuario@localhost , that is, local access only.

If you have administrative access to the server, you must add access to usuario@% to access from anywhere (% is the "wildcard", allowing access from any host); or even usuario@PREENCHA_SEU_HOST_ESPECIFICO for example if you need external access only by a machine.

An example command to authorize a user on any host and on all tables:

CREATE USER 'meuusuario'@'%' IDENTIFIED BY 'senhadousuario';
GRANT ALL PRIVILEGES ON *.* TO 'meuusuario'@'%';

Note that you do not always want all the privileges for the user, so it is better to granulate the access, according to the intended use. See grant documentation (en) for more details.

  

If you do not have administrative access, try changing it with the support of your hosting.

    
11.02.2014 / 18:47
1
  

Access denied for user ...

You are saying that the user you are using does not have access. Check the access data (host, user and password), the server configuration should be different from your local configuration.

    
11.02.2014 / 18:27