I've had a lot of trouble handling an access DB table that contains the field quantità_gc
which is a double field and has an accent on the letter à
. Using many examples I managed to set up a php code which at the moment no longer gives me errors, but at the same time it doesn't give me a numeric result but rather a string
array(1) {
["quantity_gc"]=>
string(12) "quantity_gc"
}
I ask you where I'm wrong and if it is possible to find a solution. Thanks in advance
Here is my code
<?php
$dsn = "odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:/database.mdb";
$user = '';
$password = '';
try {
$pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $e) {
die("Errore di connessione al database: " . $e->getMessage());
}
if (isset($_GET['variabile'])) {
$variabile = $_GET['variabile'];
$stmt = $pdo->prepare("SELECT 'quantità_gc' FROM magazzino WHERE id = :variabile");
$stmt->bindParam(':variabile', $variabile, PDO::PARAM_STR);
$stmt->execute();
$quantità_gc = $stmt->fetchColumn();
if ($quantità_gc !== false) {
// Applica l'encoding UTF-8 al valore del campo 'quantità_gc'
$output = ['quantità_gc' => mb_convert_encoding($quantità_gc, "UTF-8", 'auto')];
var_dump($output);
// Restituisci i risultati come JSON
//echo json_encode($output);
} else {
// Risultati non trovati o errore nella query
echo json_encode(['error' => 'Risultati non trovati o errore nella query']);
}
}
?>
PS: I already have tried many syntax for this query,
SELECT '[quantità_gc]' FROM magazzino WHERE id = :variabile
or
SELECT [quantità_gc] FROM magazzino WHERE id = :variabile
all gives errors