易截截图软件、单文件、免安装、纯绿色、仅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']一样


相关文档:

关于重新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. ......

Mysql编译安装参数优化

 1. -static  13%
   --with-client-ldflags=-all-static
   --with-mysqld-ldflags=-all-static
静态链接提高13%性能
2. -pgcc  1%
   CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
     CXXFLAGS="-O3 -mpentiumpro -mstack-alig ......

给php代码添加phpdocumentor规范的注释

 PHPDocument是从你的源代码的注释中生成文档,因此在给你的程序做注释的过程,也就是你编制文档的过程。
  从这一点上讲,PHPdoc促使你要养成良好的编程习惯,尽量使用规范,清晰文字为你的程序做注释,同时多多少少也避免了事后编制文档和文档的更新不同步的一些问题。
  在phpdocumentor中,注释分为文档性注 ......

PHP 连接mysql

 <?
$_mysqlhost="localhost";
$_mysqluser="root";
$_mysqlpass="";
$_mysqldata="mydata";
$_connect=mysql_connect($_mysqlhost,$_mysqluser,$_mysqlpass) or die ("错误".mysql_error());
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $ ......

mysql的中文乱码问题

 这段时间被这个困扰了很久,通过修改配置文件,终于把这个问题解决了。
自己在网上也找了很多关于解决这个问题的方法,但是都讲的不太清楚,所以今天在这重新说下这个问题。
我的解决方法是通过修改mysql的配置文件my.ini,方法如下:
在my.ini中可以发现有这么一段代码:
[client]
port=3306
[mysql]
default ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号