av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

php語言

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

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

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

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

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

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

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

  if (!$con) {

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

  }

  $database="my_db_name";

  $sqlDatabase = 'create database '.$database;

  if(mysql_query($sqlDatabase, $con))

  {

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

  }

  else

  {

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

  }

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

  /************************在數(shù)據(jù)庫中創(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***************************************/

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

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

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

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

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

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

  {

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

  }

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

  mysql_close();

  ?>

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

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

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

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

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

PHP訪問數(shù)據(jù)庫04-27

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

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

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

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