PHP

[PHP] MySql 연결(DB연동) new mysqli()

chsr 2020. 5. 13. 11:23
728x90
반응형
<?php
  $mysqli = new mysqli( $localhost, $user, $password );
  $mysqli -> set_charset("utf8"); 

  // Check connection
  if( $mysqli -> connect_errno ) {
     echo "Failed to connect to MySql: " . $mysqli -> connect_error ;
     exit();
  }
?>

 

#예제 (PHP 웹 페이지 호출 시 DB 테이블에 값 넣기)

<?php
	$mysqli = new mysqli( $localhost, $user, $password );
	$mysqli -> set_charset("utf8"); 
    
	$selSql = "
		INSERT INTO table_name( column1, column2 )
		VALUES ( 'value1', 'value2' )
	";
	mysqli_query($mysqli, $selSql);
?>
728x90
반응형