欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

php語(yǔ)言

PHP如何創(chuàng)建數(shù)據(jù)庫(kù)

時(shí)間:2025-04-18 18:39:35 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

PHP如何創(chuàng)建數(shù)據(jù)庫(kù)

  MySQL是最流行的開(kāi)源數(shù)據(jù)庫(kù)服務(wù)器,那我要使用PHP在MySQL的數(shù)據(jù)庫(kù)創(chuàng)建一張表,實(shí)現(xiàn)通過(guò)PHP操作數(shù)據(jù),那我們先要獲取連接,拿到MySQL數(shù)據(jù)庫(kù)的賬號(hào)密碼。下面就跟隨小編一起來(lái)看看吧!

  PHP創(chuàng)建數(shù)據(jù)庫(kù)

  $con = mysql_connect('localhost', 'root', 'root');

  /************************在數(shù)據(jù)庫(kù)中創(chuàng)建表*************************/

  if (!$con) {

  die ('連接數(shù)據(jù)庫(kù)出錯(cuò): ' . mysql_error());

  }

  $database="my_db_name";

  $sqlDatabase = 'create database '.$database;

  if(mysql_query($sqlDatabase, $con))

  {

  echo "恭喜你,數(shù)據(jù)庫(kù)".$database."創(chuàng)建成功了!";

  }

  else

  {

  echo "創(chuàng)建數(shù)據(jù)庫(kù)出錯(cuò),錯(cuò)誤號(hào):".mysql_errno()." 錯(cuò)誤原因:".mysql_error();

  }

  /******************************end***************************************/

  /************************在數(shù)據(jù)庫(kù)中創(chuàng)建表*************************/

  mysql_select_db("my_db_name",$con);

  $sqlTable="create table my_table_name (

  id int unsigned not null auto_increment primary key,

  a var20),

  b var2),

  c var1))";

  if(mysql_query($sqlTable))

  {

  echo "恭喜你,數(shù)據(jù)表創(chuàng)建成功了!";

  }

  else

  {

  echo "創(chuàng)建數(shù)據(jù)表出錯(cuò),錯(cuò)誤號(hào):".mysql_errno()." 錯(cuò)誤原因:".mysql_error();

  }

  /******************************end***************************************/

  /*************************在表中寫(xiě)入數(shù)據(jù)*********************************/

  //保證已經(jīng)執(zhí)行:

  //mysql_connect("localhost","username","passcode");//連接MySQL

  //mysql_select_db("db_name");//選擇數(shù)據(jù)庫(kù)

  $sql = " into my_table_name(a,b) values ('123','45')"; //'--'單引號(hào)內(nèi)可以是變量

  if(mysql_query($sql))//借SQL語(yǔ)句插入數(shù)據(jù)

  {

  echo "恭喜你,表中寫(xiě)入數(shù)據(jù)成功了!";

  }

  /******************************end***************************************/

  mysql_close();

  ?>

【PHP如何創(chuàng)建數(shù)據(jù)庫(kù)】相關(guān)文章:

PHP如何插入數(shù)據(jù)庫(kù)06-09

php如何連接數(shù)據(jù)庫(kù)05-19

如何在PHP中連接MySQL數(shù)據(jù)庫(kù)04-13

php網(wǎng)站如何連接到遠(yuǎn)程mysql數(shù)據(jù)庫(kù)04-11

PHP訪問(wèn)數(shù)據(jù)庫(kù)04-27

php數(shù)據(jù)庫(kù)備份腳本05-25

PHP怎么插入數(shù)據(jù)庫(kù)07-09

PHP插入數(shù)據(jù)庫(kù)的方法07-03

PHP數(shù)據(jù)庫(kù)連接的方法05-23