PHP Mysql查询

来源:互联网 发布:php构造函数的作用 编辑:程序博客网 时间:2024/05/17 02:43
ZendStudio: Alt + right / Alt + left  // skip to the last edit place


$_POST // read occurence of $_POST  PHP $_POST and $_GET method to send data to 


PHP is not strong-typeing ,so there is no need to definite return type when generate a method 


is_numeric --  检测变量是否为数字或数字字符串 


parent::__construct ( $host, $user, $pwd, $dbname );  // call the constructor of parent. equal to DataBase ::_construct
$sql = "select wealth from user where uid= +$uid";  // '+' 连接查询字符串
mysql_fetch_array --  从结果集中取得一行作为关联数组,或数字数组,或二者兼有 




如果用了 MYSQL_BOTH,将得到一个同时包含关联和数字索引的数组。用 MYSQL_ASSOC 只得到关联索引(如同 mysql_fetch_assoc() 那样),用 MYSQL_NUM 只得到数字索引(如同 mysql_fetch_row() 那样)。 


注: 该函数返回的字段名是大小写敏感的。


2. 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);
?>  
 

原创粉丝点击