易截截图软件、单文件、免安装、纯绿色、仅160KB

PHP中mysql_fetch_array()和mysql_fetch_row()的区别

 最近在做PHP与数据库交互的project,急于求成,模仿了下例子就开始动手,结果误把mysql_fetch_array写成了mysql_fetch_row,囧事来了,发现返回的数组居然是index=>value的形式,而明明记得是field name=>value的哈,查手册才明白。
1. mysql_fetch_array的函数原型是
array mysql_fetch_array ( resource $result [, int $result_type= MYSQL_BOTH ] )
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
2. 这就很明白了,若设定不同的参数,mysql_fetch_array()可以做到mysql_fetch_row()和mysql_fetch_assoc()的功能,而后两个函数就只接受第一个参数,返回的分别是associative=>value, index=>value的数组
3.MYSQL_BOTH是什么效果呢,测试了下
Sql: select firstname,lastname from table where id="c01";
$array=mysql_fetch_array($result,MYSQL_BOTH);
$array[0]和$array['firstname']一样


相关文档:

通过show status 来优化MySQL数据库

 
2009年10月30日 星期五 22:53
1, 查看MySQL
服务器配置信息
mysql> show variables;
mysql> show variables;
2, 查看MySQL服务器运行的各种状态值
mysql> show global status;
mysql> show global status;
3, 慢查询
mysql> show variables like '%slow%';  
+--------------- ......

关于重新apache后无法载入mysql扩展解决办法

网上很多写在windows下无法载入mysql扩展解决办法,但是在liunx下的就没几个,以下是在liunx下的解决办法
 重装后php不会自动把mysql.so扩展加上去,要
sudo vim /etc/php5/apache2/conf.d/pdo.ini
加入extension=mysql.so就可以了
其实也可以在 /etc/php5/apache2/php.ini中加入
也可以在/etc/php5/apache2/conf. ......

php的yii框架关联查询

假如有两个表: user  和 articles 表
结构:
user: (id, name)
articles: (id,user_id,title,content)
其中user.id 和 user_id 关联
在user的 model中的 relations方法里面加:
return array('articles'=>array(self::HAS_MANY,'articles','user_id'));
在articles的 model中的 relations方法里面加:
......

php引用文件方式

 引用文件的方法有2种:
1、require
require("conn.php"); 一般放在页面的第一行,做为该页执行的一部分,首先执行require内的conn.php 然后再执行下面的代码
2、include
include("header.php");当程序到达这里的时候才会执行include的 header.php ......

关于php里的include

 在以前的做的例子中遇到过重复的加载的错误 额 那个是通过include_once()来解决 或者不让他重复加载把重复的include()去掉一个或多个,最终只剩下一个这样问题就解决了,但今天遇到的问题就棘手了 说是找不到文件。
     事情是这样的 ,今天在文件夹里再新建了一个文件夹,然后以前includ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号