您好,欢迎访问一九零五行业门户网

PHP怎么插入数据库_PHP教程

php如何插入数据库
$ostype=$_post['ostype'];
$uuid=$_post['uuid'];
$nowtime=time();
$username='xxxx';
$userpass='xxxx';
$dbhost='localhost';
$dbdatabase='xxx';
//生成一个连接
$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'=>'链接数据库失败');
}
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'=>'插入数据库成功');
}
else {
$ret_json=array('code'=>1002, 'message'=>'插入数据库失败');
}
}
$jobj=new stdclass();
foreach($ret_json as $key=>$value){
$jobj->$key=$value;
}
echo ''.json_encode($jobj);
?>
为嘛插入数据库失败呢
id是自增的主键,lastdate是date类型
------解决方案--------------------
报错提示什么?
如果lastdate是date类型 $nowtime=date(‘y-m-d’);
如果lastdate是datetime类型$nowtime=date(‘y-m-d h:i:s');
------解决方案--------------------
echo mysql_error(); 报什么错误没有
------解决方案--------------------
少了引号了。
$result = mysql_query(insert into t_dblocal_userinformation (id, ostype, uuid, lastdate) values (null, '$ostype', '$uuid', '$nowtime'));
------解决方案--------------------
引用:
少了引号了。
$result = mysql_query(insert into t_dblocal_userinformation (id, ostype, uuid, lastdate) values (null, '$ostype', '$uuid', '$nowtime'));同意
------解决方案--------------------
第一个 想楼上那样说的 引号的问题
第二个 你的time()是返回的时间戳,和date类型对应不上吧 要转化处理一下才行
http://www.bkjia.com/phpjc/820403.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/820403.htmltecharticlephp如何插入数据库 $ostype=$_post['ostype']; $uuid=$_post['uuid']; $nowtime=time(); $username='xxxx'; $userpass='xxxx'; $dbhost='localhost'; $dbdatabase='xxx'; //生成一个连...
其它类似信息

推荐信息