php页面的sql语句执行成功,数据库不更新解决方法

WBOY
Release: 2016-06-13 11:56:49
Original
1776 people have browsed it

php页面的sql语句执行成功,数据库不更新

本帖最后由 h9zhou 于 2014-05-10 22:25:35 编辑 我做一个关于投票的页面,数据库连接成功了,下面是执行sql的方法,查询不报错,返回2,但是数据库数据不更新
但是在phpmyadmin执行sql成功也能更新数据
$sql="update vote set num=num+1 where name='布什' ";
Copy after login

public function execute_dml($sql){<br />			$b=mysql_query($sql,$this->conn) or die("执行失败!".mysql_error());<br />			if(!$b){<br />				return 0;//执行失败<br />			}else{<br />				if(mysql_affected_rows($this->conn)>0){<br />					return 1;//表示执行ok<br />				}else{<br />					return 2;//表示没有行受到影响<br />				}				<br />			}	<br />		}
Copy after login


我感觉代码应该没问题,应该是其他问题
------解决方案--------------------
如果不是其他的问题,那就可能是编码的问题。比如‘布什’ 这个在页面中是UTF-8的编码而数据库中是GBK的。
建议使用主键查询,还能保证唯一性。
------解决方案--------------------
编码问题吧,你的表是什么编码,有没有执行set names utf8 语句。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!