欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

實(shí)例講解通過​PHP創(chuàng)建數(shù)據(jù)庫

 更新時(shí)間:2019年01月20日 09:08:01   投稿:laozhang  
在本篇文章里小編給大家分享了關(guān)于如何通過​PHP創(chuàng)建數(shù)據(jù)庫的知識(shí)點(diǎn)內(nèi)容,有需要的朋友們學(xué)習(xí)下。

數(shù)據(jù)庫是相互關(guān)聯(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服務(wù)器的連接

(2)如果連接成功,編寫SQL查詢以創(chuàng)建數(shù)據(jù)庫并將其存儲(chǔ)在字符串變量中

(3)執(zhí)行查詢

(4)關(guān)閉數(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)建一個(gè)為newDemo的數(shù)據(jù)庫

$sql = "CREATE DATABASE newDemo";

//mysqli_query() 函數(shù)用于執(zhí)行某個(gè)針對數(shù)據(jù)庫的查詢。

if($conn->query($sql) === TRUE){

 

  echo "數(shù)據(jù)庫創(chuàng)建成功";

}

else {

  echo "Error creating database: " . $conn->error;

}

//關(guān)閉數(shù)據(jù)庫

$conn->close();

?>

效果圖:

相關(guān)文章

最新評論