본문 바로가기
WEB/PHP

[PHP] MySQL_SELECT : mysqli_fetch_row();

by 겅아링 2020. 9. 8.
반응형

mysqli_fetch_row();

: 일반 배열 형태로 결과값을 반환.

배열의 인덱스로 접근

 

실행결과>

select * from testTBL;

db  데이터

id 칼럼이 0번째

data 칼럼이 1번째 로 반환

 <?php
   $dbName = "testdDB";
   $tblName = "testTBL";

  $conn = mysqli_connect("localhost", "root", "111111");
  mysqli_select_db($conn, $dbName);
  
  $query="select * from ${tblName}";
  $result = mysqli_query($conn, $query);
  
  while ($row = mysqli_fetch_row($result)){
    print_r($row);
    echo "<br />" . $row[0] . "  : ". $row[1] ."<br />";
  }

?>

 

결과 >

mysqli_fetch_assoc($result)를 실행하면
$row의 0번째 인덱스 ($row[0])는 id칼럼의 데이터를 가르킴 =>1
$row의 1번째 인덱스 ($row[1])는 data칼럼의 데이터를 가르킴 =>홍길동
while문으로 커서이동후 반복출력

 

반응형

'WEB > PHP' 카테고리의 다른 글

[PHP] MySQL_SELECT : mysqli_fetch_array();  (0) 2020.09.08
[PHP] MySQL_SELECT : mysqli_fetch_assoc();  (0) 2020.09.08
[PHP] MySQL_INSERT : mysqli, PDO  (0) 2020.09.08
[PHP] MySQL_CREATE : mysqli, PDO  (0) 2020.09.08
[PHP] MySQL 연결하기 : mysqli, PDO  (0) 2020.09.08