亚洲一级免费看,特黄特色大片免费观看播放器,777毛片,久久久久国产一区二区三区四区,欧美三级一区二区,国产精品一区二区久久久久,人人澡人人草

php語(yǔ)言

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

時(shí)間:2025-03-09 00:34:20 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

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

  PHP是一種通用開源腳本語(yǔ)言。語(yǔ)法吸收了C語(yǔ)言、Java和Perl的特點(diǎn),利于學(xué)習(xí),使用廣泛,主要適用于Web開發(fā)領(lǐng)域。以下是小編為大家搜索整理PHP如何插入數(shù)據(jù)庫(kù),希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  $ostype=$_POST['ostype'];

  $uuid=$_POST['uuid'];

  $nowtime=time();

  $username='XXXX';

  $userpass='XXXX';

  $dbhost='localhost';

  $dbdatabase='XXX';

  //生成一個(gè)連接

  $db_connect=mysql_connect($dbhost,$username,$userpass) or die("Unable to connect to the MySQL!");

  $ret_json;

  if(!$db_connect) {

  $ret_json=array('code'=>1001, 'message'=>'鏈接數(shù)據(jù)庫(kù)失敗');

  }

  else {

  mysql_select_db($dbdatabase,$db_connect);

  $result = mysql_query("INSERT INTO t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, $ostype, $uuid, $nowtime)");

  if ($result) {

  $ret_json=array('code'=>1000, 'message'=>'插入數(shù)據(jù)庫(kù)成功');

  }

  else {

  $ret_json=array('code'=>1002, 'message'=>'插入數(shù)據(jù)庫(kù)失敗');

  }

  }

  $jobj=new stdclass();

  foreach($ret_json as $key=>$value){

  $jobj->$key=$value;

  }

  echo ''.json_encode($jobj);

  ?>

  為嘛插入數(shù)據(jù)庫(kù)失敗呢??

  ID是自增的主鍵,LASTDATE是DATE類型

  ------解決方案--------------------

  報(bào)錯(cuò)提示什么?

  如果LASTDATE是DATE類型 $nowtime=date(‘Y-m-d’);

  如果LASTDATE是DATETIME類型$nowtime=date(‘Y-m-d H:i:s');

  ------解決方案--------------------

  echo mysql_error(); 報(bào)什么錯(cuò)誤沒有

  ------解決方案--------------------

  少了引號(hào)了。

  $result = mysql_query("INSERT INTO t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, '$ostype', '$uuid', '$nowtime')");

  ------解決方案--------------------

  引用:

  少了引號(hào)了。

  $result = mysql_query("INSERT INTO t_dblocal_userinformation (ID, OSTYPE, UUID, LASTDATE) VALUES (NULL, '$ostype', '$uuid', '$nowtime')");同意

  ------解決方案--------------------

  第一個(gè) 想樓上那樣說的 引號(hào)的問題

  第二個(gè) 你的time()是返回的時(shí)間戳,和date類型對(duì)應(yīng)不上吧 要轉(zhuǎn)化處理一下才行

【PHP如何插入數(shù)據(jù)庫(kù)】相關(guān)文章:

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

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

PH如何插入數(shù)據(jù)庫(kù)08-11

PHP大批量插入數(shù)據(jù)庫(kù)的方法01-05

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

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

PHP大批量插入數(shù)據(jù)庫(kù)的3種方法05-23

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

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