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


相关文档:

Php Xml解析之DOMDocument使用方法浅解

 用到的XML文件还以“Php Xml处理之simplexml使用方法浅谈”一文中的XML为例,文件名为:me.xml。代码如下:
PHP XML处理XML代码
<?
xml

version
=
"1.0"

encoding
=
"utf-8"
?>
  
<
phplamp
>
  
    
& ......

MYSQL复制的几种模式

 MySQL 5.1 中,在复制方面的改进就是引进了新的复制技术:基于行的复制。
MYSQL复制的几种模式
MySQL 5.1 中,在复制方面的改进就是引进了新的复制技术:基于行的复制。
简言之,这种新技术就是关注表中发生变化的记录,而非以前的照抄 binlog 模式。
从 MySQL 5.1.12 开始,可以用以下三种模式来实现:
-- 基于 ......

PHP连接MysqL

连接:
$conn=mysql_connect ("localhost:3306", "username", "password");
mysql_select_db("DBname");
读:
$exec="select * from stu";
$result=mysql_query($exec);
while($rs=mysql_fetch_object($result))
{
    echo $rs->id." & ......

php中常用函数技巧

1.随机字符序列生成函数:
 <?php
//用于验证码序列生成等..
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars)-1;
$length=4;//长度自行设定
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < ......

关于php里的include

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