pdo mysql
true));
//$votepdo = new pdo();
//$pdoconn ->setattribute(pdo::attr_persistent,true);
echo success
;
}
catch(pdoexception $e) {
echo $e->getmessage();
}
$result=$votepdo->query(select * from uz_types);
var_dump($result);
$votepdo->query(insert into uz_types (typename)values('啊啊啊'));
echo count=.$count.
;
//$result->setfetchmode(pdo::fetch_assoc);
print_r($result);
if(empty($result))
{
echo null;
}else
{
echo have.count($result).datas;
}
echo count($result);
foreach($result as $k=>$v)
{
echo $v['typename'];
};
?>
//这里是页面输出的结果
success
bool(false) count=
null1
//
php.ini 已经配置好了啊。
没有报错 说明链接上了吧 但是为什么会是这个输出呢?
求解求解啊~
回复讨论(解决方案) var_dump($result);
$arr = $votepdo->errorinfo();
print_r($arr); //贴出这个结果看看
array ( [0] => s1000 [1] => 0 [2] => unknown initial character set index '45' received from server. initial client character set can be forced via the 'characterencoding' property. ) count=
编码错了??
打印出 success
表示 $votepdo = new pdo(mysql:host=127.0.0.1;dbname=lego... 执行正确
打印出 bool(false)
表示 $result=$votepdo->query(select * from uz_types); 执行失败
打印出 count=
正常
echo count=.$count.
; 中 $count 并未赋值
既然 $result 为假
那么 if(empty($result)) 成立
打印出 null 就很正常了
打印出 success
表示 $votepdo = new pdo(mysql:host=127.0.0.1;dbname=lego... 执行正确
打印出 bool(false)
表示 $result=$votepdo->query(select * from uz_types); 执行失败
打印出 count=
正常
echo count=.$count.
; 中 $count 并未赋值
既然 $result 为假
那么 if(empty($result)) 成立
打印出 null 就很正常了
那query为什么会失败 麻烦能解答下吗?
你的库,我怎么知道为什么失败
print_r($votepdo->errorinfo());
看看错误信息
你的库,我怎么知道为什么失败
print_r($votepdo->errorinfo());
看看错误信息
我在2楼贴了,麻烦看下。
var_dump($result);
$arr = $votepdo->errorinfo();
print_r($arr); //贴出这个结果看看
array ( [0] => s1000 [1] => 0 [2] => unknown initial character set index '45' received from server. initial client character set can be forced via the 'characterencoding' property. ) count=
$votepdo = new pdo(mysql:host=127.0.0.1;dbname=legou, 'root', '2sinilei.',array( pdo::attr_persistent => true,pdo::mysql_attr_init_command => 'set names \'utf8\''));
这样试一下看看
$votepdo = new pdo(mysql:host=127.0.0.1;dbname=legou, 'root', '2sinilei.',array( pdo::attr_persistent => true,pdo::mysql_attr_init_command => 'set names \'utf8\''));
这样试一下看看
可以读出来了,是编码问题 编码不统一就读不出数据.谢谢斑竹啦。