Home > Backend Development > PHP Tutorial > php,mysql插入报错解决思路

php,mysql插入报错解决思路

WBOY
Release: 2016-06-13 11:48:18
Original
1926 people have browsed it

php,mysql插入报错
直接在mysql里插入这句就没问题...写到php里就报错说Warning: mysqli_query() expects at least 2 parameters, 1 given in D:\xampp\htdocs\ca\connect.php on line 12
错误里的line 12指的是php代码里的$res=mysqli_query($sql);这行

<?php<br />$mysql=mysqli_connect("localhost","root","","leo");<br />$sql="insert into doc (name,size,loc) values('name1','size1','loc1')";<br />$res=mysqli_query($sql);<br />if($res===TRUE)<br />{<br />	echo '插入完成';<br />	}<br />	else echo '插入失败';<br />	mysqli_close($mysql);<br />?>
Copy after login


------解决方案--------------------
函数原型
mixed mysqli_query ( mysqli link, string query [, int resultmode] )
link 不可缺省
应该写作
$res = mysqli_query($mysql, $sql);
------解决方案--------------------
<br />mysqli_query($mysql,$sql);//必须要2个参数<br />
Copy after login


要学会查手册

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