Home > php教程 > php手册 > mysql与php

mysql与php

WBOY
Release: 2016-06-06 20:00:14
Original
1252 people have browsed it

mysqli中的 i代表improved 一般调用过程: span style=font-size:18px;./span..$db = mysql_connect(...) or die(connecting error...);//连接数据库;$query=select name from users limit 1;//组装查询串;$result = mysqli_query($db,$query) or die(quer

mysqli中的 i代表improved
一般调用过程:

<span style="font-size:18px;">.</span>..
$db = mysql_connect(...) or die("connecting error...");//连接数据库;
$query="select name from users limit 1";//组装查询串;
$result = mysqli_query($db,$query) or die("querying error...");//执行查询;
$row = mysqli_fetch_array($result);//获取查询结果
$user_name = $row['name'];
mysqli_close($db);//关闭连接。
...
Copy after login


在开发项目的时候,写一个Mysqls封装类,里面封装了各种方法,包括构造等基本方法。调用的时候可能就是这样了:

...
$ms = new Mysqls;
$sql  ="select name from users limit 1";
$data = $ms->getRow($sql);
if(!$data){
    $user_name = $data['name'];
}
...
Copy after login


取多条
while($row = mysqli_fetch_array($result))...
foreach($data as $m)...



命令行下,使用数据库前先执行USE命令(phpMyAdmin不用)
命令行下的DESCRIBE命令
尽量避免使用  *,用字段代替
尽量每条语句都加limit
不使用连接操作
多看mysql的优化手册。。。。。。


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template