1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

query構文を用いてPHPでSQL操作(テーブル作成と削除、SQLエラーの表示)

Last updated at Posted at 2022-03-27

・query構文を用いてPHPでSQL操作(テーブル作成と削除、SQLエラーの表示)
●query構文
DB接続インスタンス->query("SQL操作");
※SQL操作・・・create, drop, delete, insert, update等
●テーブル作成
DB接続インスタンス->query("create table テーブル名(カラム名 カラム型, ...)");
●テーブル削除
DB接続インスタンス->query("drop table if exists テーブル名");
●SQLのエラーの表示
echo DB接続インスタンス->error;

例)

<?php
$db = new mysqli("localhost:8889", "root", "root", "mydb");
$db->query("drop table if exists test");
$success = $db->query("create table test(id INT)");
if ($success) {
    echo "テーブルを削除後、作成しました";
} else {
    echo "SQLが正常に動作しませんでした";
    echo $db->error;
}
?>

補足画像)
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?