zoukankan      html  css  js  c++  java
  • 有关wordpress wpdb类方法的一些整理

    主要函数:

    get_results

    function get_results($query = null, $output = OBJECT)

    返回SQL查询结果,返回值是一个由多行数据array组成的array,array(array(‘field1’=> ‘value1’, ‘field2’=> ‘value2’, …, ‘filedN’ => ‘valueN’));

    例子:

    foreach($db->get_results(‘select * from books’) as $book) {
    	echo “name: $book->name<br>”;
    	echo “author: $book->author<br>”;
    }

    get_row

    function get_row($query = null, $output = OBJECT, $y = 0)

    返回SQL查询的指定行内容

    例子:

    $book = $db->get_row(‘select * from books’, 3);
    echo “name: $book->name<br>”;
    echo “author: $book->author<br>”;

    get_col

    function get_col($query = null , $x = 0)

    返回SQL查询的指定字段内容

    例子:

    foreach ($db->get_col(‘select * from books’, 1) as $author) {
    	echo “author: $author”;
    }

    get_var

    function get_var($query=null, $x = 0, $y = 0)

    返回SQL查询的指定位置的值

    例子:

    foreach ($db->get_var(‘select * from books’, 2, 1) {
    	echo “author: $author”;
    }

    insert

    function insert($table, $data, $format = null)

    向表中插入内容

    例子:

    $db->insert(‘books’, $array(‘name’=>’Breaking Bad’, ‘author’=>’David Lee’));

    update

    function update($table, $data, $where, $format = null, $where_format = null)

    修改表中的数据

    例子:

    $db->update( ‘books’, array( ‘name’ => ‘Breaking Bad’), array( ‘id’ => 326 ));
  • 相关阅读:
    事务
    触发器
    SQL 存储过程
    SQL 视图 索引
    SQL 函数
    SQL查询语句练习
    SQL约束
    SQL Server 数据的添加修改删除和查询
    The type ProxyGenerator is not accessible due to restriction on required library问题的解决
    ==与equals
  • 原文地址:https://www.cnblogs.com/leavenup/p/2670443.html
Copyright © 2011-2022 走看看