PDO works on localhost, but not on webservice

Asked

Viewed 61 times

1

I made an app and it runs on localhost no problem at all. When I switched to hosting it simply does not read the SQL commands by PDO (it is enabled on php.ini).

Connection seems to work fine, reports no errors.

<?php  
   try {
      $conn = new PDO('mysql:host=xxxxx.xxxxxxx.xxx.xx;dbname=xxxxx', "xxxxx", "xxxxx");
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    ?>

But when I try a search with SQL and PDO nothing appears:

<?PHP
include ("conexao.php");

$login = $_POST["login"];
$senha = $_POST["senha"];
$usuario = 0;

echo "Teste 1"; 

$query = $pdo ->prepare("SELECT * FROM login WHERE login = :login AND senha = :senha");
$query->bindValue(":login", $login);
$query->bindValue(":senha", $senha);
$query->execute();
$linha = $query->fetch(PDO::FETCH_ASSOC);
$aux = $query->rowCount();

  echo "Teste 2";
  // (resto do código, mas não chega nessas parte, testei com echo)

Edit: I deleted php.ini and let it run from the hosting itself, it’s working now

  • Is php running on the same host as the database? Does it return any errors? Is your PHP set up to display errors? - If you are accessing the database externally, the user is allowed external access?

  • "- does not report errors" I’ve already found a mistake: $conn = new PDO('... and then you use $query = $pdo ->prepare(".... It’s wrong! It wasn’t supposed to work on yours localhost. Weird, huh!

  • @Lipespry this error was mine to publish here, the variables are the same, I was doing several tests to try to find the error. Answering the questions, the php files and the database are in the same hosting. No error is returned. I gave full permission to the user.

  • Your PHP is configured to display errors? Because it is hosting, it is configured not to display by default (production).

  • not configured for this, by the way, nor know how to display php errors in a webservice

  • Open that link there that has the ini_set which can be enabled when running the script...

  • I deleted php.ini and left it using the one of the hosting and is working for what it seems

  • What do you mean?! Ohxi! This is not appropriate! Kkkk

  • I have no idea why, but if it worked, I hope it doesn’t cause any more problems later. but the hostgator itself recommends using theirs, tested and worked

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.