Error handling and fetching MySQL data using PHP -
this question has answer here:
- can mix mysql apis in php? 5 answers
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?
php error reporting can turned on using error_reporting() function. need handle mysql errors. handling them depends on chosen module use connect it.
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
Post a Comment