PHP PDO Mysql Update
카테고리 없음

PHP PDO Mysql Update

by nocagklhw 2020. 7. 28.
<?php 
try {
  $pdo = new PDO('mysql:host=localhost;dbname=데이터베이스이름','root','db비번');
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  //오류 내용 호출

  $sql = 'UPDATE joke SET jokedate="2020-06-30" WHERE joketext LIKE "%프로그래머%"'; //프로그래머를 포함하고 있는 컬럼을 2020년 6월 30일로 날짜를 바꾸어라
  $affectedRows = $pdo->exec($sql);

  $output = '갱신된 row: '.$affectedRows . ' 개';
} catch (PDOException $e) {
  $output = 'DB 접속 불가'.'<br>'.$e;
  $e->getMessage().', 위치: '. 
  $e->getFile() . ':' . $e->getLine();
}

?>

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php echo $output; ?>
</body>
</html>

 

 

 

 

 

댓글


TOP

TEL. 02.1234.5678 / 경기 성남시 분당구 판교역로