Home  >  Article  >  Backend Development  >  php mysql 数据操作有关问题

php mysql 数据操作有关问题

WBOY
WBOYOriginal
2016-06-13 12:05:23774browse

php mysql 数据操作问题
求前辈指导!

如图,表里面有2条数据  第一条是在phpMyAdmin插入的,第二条是从php页面插入的
org_name varchar类型  open_time timestamp 类型
php代码如下:
include_once("pay/CommonUtil.php");
include_once dirname(__FILE__).'/db/DbOperation.php';
$db = new DbOperation('z_org');
$org = array(
"org_id" => 2,
"org_name" => "北京市",
"open_time" => time()
);
$db->addObject($org);
$rs = $db->getAll();
var_dump($rs);
?>

问题:
1.从php插入的数据 汉字乱码,时间为0000-00-00 00:00:00
2.查询全表 第一条数据汉字乱码,第二条正常了
array(2) { [0]=> array(3) { ["org_id"]=> string(1) "1" ["org_name"]=> string(3) "???" ["open_time"]=> string(19) "2014-08-23 18:35:18" } [1]=> array(3) { ["org_id"]=> string(1) "2" ["org_name"]=> string(9) "北京市" ["open_time"]=> string(19) "0000-00-00 00:00:00" } } 
------解决方案--------------------
程序编码是什么?换成和phpmyadmin编码一样的
------解决方案--------------------

('set names utf8')
不是
(‘set names utf_8')
------解决方案--------------------
$org = array(
"org_id" => 2,
"org_name" => "北京市",
"open_time" => 'now()'
);
用数据库的时间函数较好

你 date 得到的时间不对,是因为你的树区没有设置好
------解决方案--------------------
php当中没有now()函数
now()  等价 date("Y-m-d H:i:s" );

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn