i want to show the data from the database and csv file. I*m using oops in the php where i show data from both the database and csv but in the csv function there is following error:
syntax error, unexpected '$f' (T_VARIABLE), expecting function (T_FUNCTION) in D:\xampp\htdocs\factory\4.php on line 71
Code:
<?php
interface IDatabase {
function connect();
function readCSV();
}
class Db implements IDatabase
{
private $connection;
private static $instance;
private function __construct()
{
$host = "localhost";
$user = "root";
$pass = "";
$name = "cart";
$this->connection = new mysqli($host, $user, $pass, $name);
if(mysqli_connect_error()) {
trigger_error("Failed to conencto to MySQL: " . mysqli_connect_error(),
E_USER_ERROR);
}
}
public function connect()
{
if (self::$instance == null) {
self::$instance = new Db();
}
return self::$instance;
}
public function query($sql)
{
$result = $this->connection->query($sql);
$records = array();
while ($row = $result->fetch_assoc()) {
$records[] = $row;
}
return $records;
}
}
$db1 = Db::connect();
$query = $db1->query("SELECT * FROM user_info");
foreach($query as $row=>$val)
{ echo '<tr>';
echo '<td>'.$val['id'].'</td>';
echo '<td>'.$val['username'].'</td>';
echo '<td>'.$val['email'].'</td>';
echo '<td>'.$val['password'].'</td>';
echo '</tr>';
}
class csv implements IDatabase{
public function readCSV($f){fclose($f);}
$f = fopen("http://localhost/csv/cr.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
$data = count($line);
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
?>
Aucun commentaire:
Enregistrer un commentaire