You're mixing mysqli with PDO exceptions try/catch, plus there's an extra bracket in your try block. Those two APIs do not mix.
See the comments in your code: (and the fixed code below that)
Sidenotes: You may want to change foreach(mysqli_fetch_array($result) as $row) to while ($row = mysqli_fetch_assoc($result))
Using foreach(mysqli_fetch_array($result) as $row) will produce repeated results of the rows and only the first letter from each row.
try {
// Setting the query and runnin it...
$result = mysqli_query($connection,"SELECT * FROM table");
if(mysqli_num_rows($result)>0)
){
// ^-- one bracket too many
foreach(mysqli_fetch_array($result) as $row) {
echo $row['rowa']. ' - '. $row['rowb']. ' - '. $row['rowc']. ' - '. $row['rowd']. ' - '. $row['rowe'].'<br />';
}
}else{
echo "QUERY IS NOT OKAY";
} // Closing the connection.
$connection = null;
}catch(PDOException $e) { // this should be catch (Exception $e)
echo $e->getMessage();
}
Change it to this:
try {
// Setting the query and runnin it...
$result = mysqli_query($connection,"SELECT * FROM `table`");
if(mysqli_num_rows($result)>0)
{
foreach(mysqli_fetch_array($result) as $row) {
echo $row['rowa']. ' - '. $row['rowb']. ' - '. $row['rowc']. ' - '. $row['rowd']. ' - '. $row['rowe'].'<br />';
}
}else{
echo "QUERY IS NOT OKAY";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
Add error reporting at the top of your file(s)
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
Rewrite:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$connection=mysqli_connect("localhost"/*hostname*/,
"username"/*username*/,
"password"/*password*/,
"dbname"/*database name*/);
try {
// Setting the query and runnin it...
$result = mysqli_query($connection,"SELECT * FROM `table`");
if(mysqli_num_rows($result)>0)
{
// use while instead of foreach
// while ($row = mysqli_fetch_assoc($result)){
foreach(mysqli_fetch_array($result) as $row) {
echo $row['rowa']. ' - '. $row['rowb']. ' - '. $row['rowc']. ' - '. $row['rowd']. ' - '. $row['rowe'].'<br />';
}
}else{
echo "QUERY IS NOT OKAY";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
mysql_...andmysqli_...are two quite separate things. You cannot mix them, you have to decide which one to use. Since the oldmysql_...connector has been deprecated a while ago you should go for the newer, more secure and flexiblemysqli_...connector. Also you want to read about the advantages of "prepared statements" to prevent vulnerability to sql injection.password, the username reallyusernameand the dbname reallydbname? If your answer is yes, you are the most careless programmer i have ever seen in my entire life.tableis a reserved word. You'll need to wrap it in backticks if you really want to use it as a table name. You'd do better to use a different table name.)too many intry {// Setting the query and runnin it... $result = mysqli_query($connection,"SELECT * FROM table"); if(mysqli_num_rows($result)>0) ){change totry {// Setting the query and runnin it... $result = mysqli_query($connection,"SELECT * FROM table"); if(mysqli_num_rows($result)>0) {@TheOkayMan