實例講解通過PHP創(chuàng)建數(shù)據(jù)庫
數(shù)據(jù)庫是相互關聯(lián)的數(shù)據(jù)的集合,我們可以從數(shù)據(jù)庫中有效地檢索,插入和刪除數(shù)據(jù),并以表格,視圖,模式等形式組織數(shù)據(jù)。今天將要介紹如何通過PHP來創(chuàng)建MySQL數(shù)據(jù)庫
PHP創(chuàng)建MySQL數(shù)據(jù)庫的基本步驟:
(1)建立PHP腳本與MySQL服務器的連接
(2)如果連接成功,編寫SQL查詢以創(chuàng)建數(shù)據(jù)庫并將其存儲在字符串變量中
(3)執(zhí)行查詢
(4)關閉數(shù)據(jù)庫
接下來在文章中將為大家具體介紹PHP創(chuàng)建數(shù)據(jù)庫的過程
<?php header("Content-Type: text/html; charset=utf8"); $servername = "localhost"; $username = "username" $password = "password" //創(chuàng)建鏈接 $conn = new mysqli($servername,$username,$password); if($conn->connect_error){ die("連接失敗" .$conn->connect_error); } //創(chuàng)建一個為newDemo的數(shù)據(jù)庫 $sql = "CREATE DATABASE newDemo"; //mysqli_query() 函數(shù)用于執(zhí)行某個針對數(shù)據(jù)庫的查詢。 if($conn->query($sql) === TRUE){ echo "數(shù)據(jù)庫創(chuàng)建成功"; } else { echo "Error creating database: " . $conn->error; } //關閉數(shù)據(jù)庫 $conn->close(); ?>
效果圖:
- MySQL創(chuàng)建數(shù)據(jù)庫并支持中文字符的操作方法
- Mysql匿名登錄無法創(chuàng)建數(shù)據(jù)庫問題解決方案
- MySql添加新用戶及為用戶創(chuàng)建數(shù)據(jù)庫和給用戶分配權限方法介紹
- mysql創(chuàng)建數(shù)據(jù)庫,添加用戶,用戶授權實操方法
- MySQL創(chuàng)建數(shù)據(jù)庫的兩種方法
- 用MySQL創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù)庫表代碼
- 創(chuàng)建數(shù)據(jù)庫php代碼 用PHP寫出自己的BLOG系統(tǒng)
- php桌面中心(一) 創(chuàng)建數(shù)據(jù)庫
- MySQL與PHP的基礎與應用專題之創(chuàng)建數(shù)據(jù)庫表
相關文章
PHP 將圖片按創(chuàng)建時間進行分類存儲的實現(xiàn)代碼
代碼功能:使用PHP巧妙將圖片按創(chuàng)建時間進行分類存儲 圖片文件屬性須取消只讀屬性,否則無法刪除2010-01-01使用PHPMailer實現(xiàn)郵件的實時發(fā)送功能
這篇文章主要為大家詳細介紹了如何使用PHPMailer 實現(xiàn)一個接收詢盤并實時同步到指定郵箱的功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2023-12-12