drupal 6 和 drupal 7 db_query 用法

// Drupal 7
// Notice the place holders are now done using the same syntax as PDOs (:uid)
// Placeholders also don't need to be quoted anymore.
$uid = 1
;
$result = db_query(
'SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid'
, array(':uid' => $uid
));
// Result is returned as a iterable object that returns a stdClass object on each iteration
foreach ($result as $record
) {
 
// Perform operations on $record->title, etc. here.
  // in this example the available data would be mapped to object properties:
  // $record->nid, $record->title, $record->created
}

// Same example in Drupal 6
$uid = 1
;
$result = db_query(
"SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = %d"
, $uid
);
while (
$record = db_fetch_object($result
)) {
 
// Perform operations on $record->title, etc. here.
}
// NOTE: db_fetch_object and db_fetch_array have been removed from D7!

?>

 

// Using the same query from above...
$uid = 1
;
$result = db_query(
'SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid'
, array(':uid' => $uid
));

// Fetch next row as a stdClass object.
$record = $result->fetchObject
(); 

// Fetch next row as an associative array.
$record = $result->fetchAssoc
();

// Fetch data from specific column from next row
// Defaults to first column if not specified as argument
$data = $result->fetchColumn(1);
// Grabs the title from the next row

// Retrieve all records into an indexed array of stdClass objects.
$result->fetchAll
();

// Retrieve all records as stdObjects into an associative array
// keyed by the field in the result specified.
// (in this example, the title of the node)
$result->fetchAllAssoc('title'
);

// Retrieve a 2-column result set as an associative array of field 1 => field 2.
$result->fetchAllKeyed
();
// Also good to note that you can specify which two fields to use
// by specifying the column numbers for each field
$result->fetchAllKeyed(0,2);
// would be nid => created
$result->fetchAllKeyed(1,0);
// would be title => nid

// Retrieve a 1-column result set as one single array.
$result->fetchCol
();
// Column number can be specified otherwise defaults to first column
$result->fetchCol($db_column_number
);

// Count the number of rows
$result->rowCount
();
?>

 

转载于:https://my.oschina.net/wangwang110/blog/9774

基于gcc的stm32环境搭建源码+文档说明.zip,个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做毕业设计的学生需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的stm32环境搭建源码+文档说明.zip基于gcc的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值