Error handling and fetching MySQL data using PHP -


this question has answer here:

i'm running hosting through godaddy , update code direct on server. instead of running local , uploading server. problem don't error messages when run locally using wamp.

right i'm trying fetch data using mysql, blank page.

require_once('../db.php');  $countyarr = mysql_query(select `county` `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 line     echo 'connected database<br/>';     }     catch(pdoexception $e)     {     echo $e->getmessage();     } ?> 

questions:

  • how activate error handling 1 wamp?
  • where go wrong in specific code?

  1. php error reporting can turned on using error_reporting() function. need handle mysql errors. handling them depends on chosen module use connect it.

  2. there 2 problems code can see. sql command needs passed string, enclose " or '. moreover, connect mysql via pdo, try execute sql command mysql module. use pdo execute sql command.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -