Home > Backend Development > PHP Tutorial > 为啥 new mysqli 会出错

为啥 new mysqli 会出错

WBOY
Release: 2016-06-13 12:47:20
Original
1303 people have browsed it

为什么 new mysqli 会出错?
$db = new mysqli('localhost', 'root', '', 'tran');
$name = 'jack';

$sql_1 = sprintf('INSERT INTO `tb_user` (name)VALUES("%s")',mysql_real_escape_string($name));

$db->query($sql_1);

为什么会出现

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in

这两个句错误的,我知道如果连不上数据库mysql_real_escape_string是会报错的,但我明明连接上了,
如果换回mysql_connect() mysql_select_db mysql_query()这样的链接就没问题

还有就是我的字段 name 设置的是not null 为什么上面的sql语句执行了抛出 Warning 这样严重的错误还会保存一个空值的?not null 不是不能为空否则不能保存的吗?

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