저는 PDO를 처음 사용합니다. 내 mysql 테이블에서 데이터를 가져 오려고합니다. 웹 및 다른 stackoverflow 응답을 둘러 보았습니다.하지만 모든 추가 코드가 추가되어 혼란스러워졌습니다. 당신이 수준의 학생들이 있습니까mysql 데이터를 가져 오는 중 PDO
<?php
$sth = $dbh->prepare("SELECT name, location, age FROM students");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_CLASS, "students");
var_dump($result);
?>
연결 정보
function getConnection()
{
$DCONFIG_server = "localhost";
$DCONFIG_DBuser = "root";
$DCONFIG_DBpass = "root";
$DCONFIG_dbname = "school";
$conn = null;
try
{
$conn = new PDO("mysql:host=$DCONFIG_server;dbname=$DCONFIG_dbname",$DCONFIG_DBuser, $DCONFIG_DBpass);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
return $conn;
}
출력 결과에 db 테이블에서 가져올 데이터가 포함되어 있습니까? '이름','위치'와'나이'? –
물론 내가 포함하는 dbconnect 파일을 가지고 있습니다. – SamXronn
위의 코드에서 출력이 없습니다. – SamXronn