PHP与MySQL交互
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-6a63b05b4f020d7d392d56642c966ce1_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>image-20220714115113128<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">函数速查</p>函数名mysqli_connect()与MySQL 数据库<span style="color: black;">创立</span>连接mysqli_close()关闭与MYSQL 数据库<span style="color: black;">创立</span>的连接mysqli_connect_errno()与MySQL 数据库<span style="color: black;">创立</span>连接时,<span style="color: black;">出现</span>错误时的错误编号mysqli_connect_error()与MySQL 数据库<span style="color: black;">创立</span>连接时,<span style="color: black;">出现</span>错误时的错误信息mysqli_query()执行SQL 语句。mysqli_errno()执行SQL 语句时,<span style="color: black;">出现</span>错误的编号mysqli_error()执行SQL 语句时,<span style="color: black;">出现</span>错误的信息mysqli_fetch_assoc()从结果集对象中取数据,按条取数据。<h2 style="color: black; text-align: left; margin-bottom: 10px;">PHP与MySQL进行交互</h2>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">PHP与MySQL交互的过程</h3><span style="color: black;">创立</span>与MySQL链接执行SQL语句,返回结果集对象从结果集对象中取数据关闭与MySQL链接<h3 style="color: black; text-align: left; margin-bottom: 10px;">与MySQL<span style="color: black;">创立</span>链接</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">直接<span style="color: black;">运用</span>PHP<span style="color: black;">供给</span>的函数</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">连接指定的MySQL服务器</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysqli_connect()</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">$db_host = "127.0.0.1";
$db_user = "root";
$db_pass = "root";
$db_name = "dvwa_201";
$link = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if(!$link){
die("MySQL Connect Error!");
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>链接成功,返回 object(mysqli)1 ;否则,返回 bool(false) 。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$link 是对象类型的变量,相当于一个"令牌"</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">连接错误时的提示</h3>错误编号错误详情<div style="color: black; text-align: left; margin-bottom: 10px;">$link = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if(!$link){
exit("[".mysqli_connect_errno()."]".mysqli_connect_error());
}</div>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">关闭与mysql服务器的连接</h3>
<div style="color: black; text-align: left; margin-bottom: 10px;">mysqli_close($link);</div>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">执SQL语句</h3>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">对数据库执行一条SQL语句</h3>
<div style="color: black; text-align: left; margin-bottom: 10px;">$sql = "select * from user;";
$results = mysqli_query($link, $sql);
if(!$results){
echo "SQL Query Error!";
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>SQL 语句正常执行,就会返回对象类型object(mysqli_result)#2的数据;否则,bool(false)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">针对</span>insert,delete ,update 等不会返回数据的SQL 语句,在执行<span style="color: black;">无</span>错误时将返回 true 。<span style="color: black;">针对</span>返回数据的SQL 语句执行成功的时候会返回结果集对象 ,<span style="color: black;">能够</span><span style="color: black;">运用</span>操作结果集对象的函数来从中获取数据</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">SQL语句错误</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>在执行SQL语句的时候<span style="color: black;">出现</span>错误,以上两个函数都将返回false。并且<span style="color: black;">能够</span><span style="color: black;">运用</span>以下函数处理错误<span style="color: black;">原由</span>:</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">if(!$results){
exit("[".mysqli_errno($link)."]".mysqli_error($link));
}</div>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">从结果集对象中取数据</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">操作结果集对象</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">函数速查</h3>函数说明mysqli_fetch_row()以索引数组的方式
你字句如珍珠,我珍藏这份情。 外贸B2B平台有哪些? 感谢你的精彩评论,为我的思绪打开了新的窗口。 谷歌外链发布 http://www.fok120.com/
页:
[1]