0

I'm running hosting through Godaddy and update the code direct on the server. Instead of running it local and then uploading it to the server. The only problem is that I don't get any error messages that I usually would get when I run it locally using WAMP.

Right now I'm trying to fetch data using MySQL, but I only get a blank page.

require_once('../db.php');

$countyArr = mysql_query(SELECT `County` FROM `Infectious_Disease_Cases_by_County`);

while($rows = mysql_fetch_array($countyArr))
{

   $rows = $rows['County'];

   echo $rows;
}


?>

db.php

<?php
    $username = "user";
    $password = "pass";
    $hostname = "localhost"; 
    $dbname = "db_test";


    try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname",$username,$password);

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
    echo 'Connected to Database<br/>';
    }
    catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

Questions:

  • How do I activate error handling like the one I get with WAMP?
  • Where do I go wrong in this specific code?
Adam
  • 329
  • 1
  • 9
  • 20

2 Answers2

2
  1. Php error reporting can be turned on using error_reporting() function. You also need to handle mysql errors. Handling them depends on your chosen module you use to connect to it.

  2. There are 2 problems with your code that I can see. The sql command needs to be passed as string, so enclose it by " or '. Moreover, you connect to mysql via pdo, but you try to execute your sql command with mysql module. Use pdo to execute the sql command.

Shadow
  • 33,525
  • 10
  • 51
  • 64
0

You need put string inside quotes:

$countyArr = mysql_query("SELECT `County` FROM `Infectious_Disease_Cases_by_County`");

To display error in php:

Check this other question

Community
  • 1
  • 1
Vinícius Fagundes
  • 1,983
  • 14
  • 24