Я написал код PHP, используя PDO. Я новичок в синтаксисе PHP, поэтому я следую документации PHP. Я получаю синтаксическую ошибку в выражении $ params = array (.... Возможно, проблема с синтаксисом - это ссылка на глобальные переменные, но это ссылка, которую я нашел в документации PHP.
Вот мой код:
<?php
/*
Sets up a PDO object for the ResDatLog table
*/
class Resdatalog
{
// database connection and table name
private $_conn;
private $_table_name = "ResDataLog";
// object properties
public $ID;
public $Location = null;
public $Temperature;
public $Humidity;
public $Pressure;
public $RecDate;
public $AmbientTemp;
public $AmbientHum;
public $AmbientPressure;
/*
constructor with $db as database connection
*/
public function __construct($db)
{
$this->conn = $db;
}
/*
Reads all columns of the entire table ($table_name)
*/
function read()
{
// select all query
$query = "SELECT *
FROM
" . $this->table_name . "
ORDER BY
id DESC";
// prepare query statement
$stmt = $this->conn->prepare($query);
// execute query
$stmt->execute();
return $stmt;
}
function insert()
{
// insert a new row into the table_name table
$sql = 'INSERT Location, Temperature, Humidity, Pressure, RecDate,
AmbientTemp, AmbientHum, AmbientPressure into '
. $this->table_name .
' VALUES (:Location,:Temperature, :Humidity,
:Pressure, :RecDate, :AmbientTemp, :AmbientHum, :AmbientPressure)';
$sth = $this->conn->prepare($sql);
$params = array(
':Location' => ResDataLog->Location,
':Temperature'=> ResDataLog->Temperature,
':Humidity'=> ResDataLog->Humidity,
':Pressure'=> ResDataLog->Pressure,
':RecDate'=> ResDataLog->RecDate,
':AmbientTemp'=> ResDataLog->AmbientTemp,
':AmbientHum'=> ResDataLog->AmbientHum,
':AmbientPressure'=> ResDataLog->AmbientPressure);
Return($$sth->execute($params));
}
}
?>