Shows this error when i connect with PDO

this error


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'result_id' in 'order clause'' in C:\xampp\htdocs\rt\new_result.php:12 Stack trace: #0 C:\xampp\htdocs\rt\new_result.php(12): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\rt\new_result.php on line 12

this is connect

<?php
$sn = "localhost";
$u = "root";
$p = "";
$db = "sresult";

$conn = mysqli_connect($sn, $u, $p, $db);
mysqli_set_charset($conn,"utf8");

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
try{
	$db = new PDO('mysql:host='.$sn.';dbname='.$db.';charset=utf8mb4', $u, $p);
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
	echo $e->getMessage();
}

I think we need to see the full code for new_result.php. It looks to me as though the error message is saying that line 12 has some SQL code using ORDER that refers to result_id but that there is no such column in the table to which the SQL command refers. (btw, I am not in any way a PHP expert).

1 Like

i fixed it, thanks