php中的mys ql函数使用 mysqlfetcharray

来源:互联网 发布:淘宝上最火的男模特 编辑:程序博客网 时间:2024/07/24 02:25

mysql_fetch_array 使用 MYSQL_NUM

<?php
    mysql_connect
("localhost","mysql_user","mysql_password") or
        die(
"Could not connect: ". mysql_error());
    
mysql_select_db("mydb");

    
$result =mysql_query("SELECT id, name FROM mytable");

    while (
$row =mysql_fetch_array($result,MYSQL_NUM)) {
        
printf ("ID: %s  Name: %s",$row[0],$row[1]);
    }

    
mysql_free_result($result);
?>


例子 3. mysql_fetch_array 使用 MYSQL_ASSOC

<?php
    mysql_connect
("localhost","mysql_user","mysql_password") or
        die(
"Could not connect: " .mysql_error());
    
mysql_select_db("mydb");

    
$result =mysql_query("SELECT id, name FROM mytable");

    while (
$row =mysql_fetch_array($result,MYSQL_ASSOC)) {
        
printf ("ID: %s  Name: %s",$row["id"],$row["name"]);
    }

    
mysql_free_result($result);
?>

例子 4. mysql_fetch_array 使用 MYSQL_BOTH

<?php
    mysql_connect
("localhost","mysql_user","mysql_password") or
        die(
"Could not connect: " .mysql_error());
    
mysql_select_db("mydb");

    
$result =mysql_query("SELECT id, name FROM mytable");

    while (
$row =mysql_fetch_array($result,MYSQL_BOTH)) {
        
printf ("ID: %s  Name: %s",$row[0],$row["name"]);
    }

    
mysql_free_result($result);
?>



0 0
原创粉丝点击