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

php語(yǔ)言

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

時(shí)間:2025-03-12 15:20:06 php語(yǔ)言 我要投稿

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

  導(dǎo)語(yǔ):PHP怎么插入數(shù)據(jù)庫(kù)呢?其實(shí)這個(gè)是一個(gè)比較簡(jiǎn)單的問(wèn)題,下面你跟著百分網(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ò)誤沒(méi)有

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

  少了引號(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è) 想樓上那樣說(shuō)的 引號(hào)的問(wèn)題

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

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

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

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

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

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

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

PHP數(shù)據(jù)庫(kù)備份腳本的方法04-06

備份php數(shù)據(jù)庫(kù)腳本的方法02-04

PHP數(shù)據(jù)庫(kù)備份腳本的方法技巧05-29

PHP數(shù)據(jù)庫(kù)連接的方法是什么02-26