Home  >  Article  >  Database  >  mysql与php_MySQL

mysql与php_MySQL

WBOY
WBOYOriginal
2016-06-01 13:06:181302browse

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);//关闭连接。...


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

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


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



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


Statement:
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