데이터베이스를 데이터베이스라고하고 테이블을 테이블이라고합니다 (테스트 용).데이터베이스에서 테이블을 보려고했지만 PHPmyAdmin의 쿼리와 일치하는데도 불구하고 잘못된 구문이 있습니다.
class Database
{
public $server = "localhost";
public $database = "database";
public $user = "root";
public $password = "";
public $row;
public $result;
//call connection method upon constructing
public function __construct(){
$this->createConnection();
}
//connection to the database
public function createConnection()
{
$this->dbLocalhost = mysql_connect($this->server, $this->user, $this->password)
or die("could not connect:".mysql_error());
mysql_select_db($this->database)
or die("Could not find the database: ".mysql_error());
}
//execute query string
public function query($queryString)
{
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
$this->result = mysql_query($queryString)
or die($queryString."<br/><br/>".mysql_error());
while($this->row = mysql_fetch_array($this->result)) {
echo "<tr>";
echo '<td>' . $this->row['id'] . '</td>';
echo '<td>' . $this->row['firstname'] . '</td>';
echo '<td>' . $this->row['lastname'] . '</td>';
echo '<td><a href="edit.php?id=' . $this->row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $this->row['id'] . '">Delete</a></td>';
echo "</tr>";
}
echo "</table>";
}
그리고 나서 함수를 호출하는 php 파일이 있습니다.
<?php
include('database.php');
$db = new Database();
$sql = "SELECT *
FROM table";
$db->query($sql);
?>
이것은 수신 오류입니다 :
SELECT *을 테이블에서
당신은 당신의 SQL 구문에 오류가 있습니다; 귀하의 MySQL 서버 버전에 해당하는 설명서를 확인하여 2 행에서 '테이블'근처에서 올바른 구문을 사용하십시오.
감사합니다.
은 테이블이라고 불리는 테이블입니까?!?! – Andbdrew
그래, 데이터베이스가 데이터베이스 – normower