Compañeros, tengo un script que desarrolle sin embargo al ser muy nuevo en este mundo el script funciona y hace su trabajo, pero me gustaria agregarle algo de serguridad.
Anteriormente usaba Mysqli
Se que existe la inyección de SQL y me gustaría evitarlo, actualmente manejo la petición a la base de datos de esta forma:
He realizado esto pero no me devuelve nada
/Connect to DB
$db_charset = 'utf8';
$dsn = "mysql:host=$db_host;dbname=$db_name;charset=$db_charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $db_user, $db_pass, $opt);
//In case of error coection show details of error
if ($pdo == null) {
die("ERROR: Could not connect. " . mysqli_connect_error());
}
//Query to obtain the data of the order
$sql = "SELECT * FROM orders WHERE order_id = '$order_id'";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
$stmt->close();
//Save the data of the order in variables
$order_id = $result[0]['order_id'];
$total_amount = $result[0]['total_amount'];
$invoice_status = $result[0]['invoice_status'];
$invoice_id = $result[0]['invoice_id'];
$date_created = $result[0]['date_created'];
//Close the connection
$pdo = null;