php的fred,PHP - Manual: cubrid_query (官方文档)

这段代码展示了如何在PHP中使用CUBRID数据库API进行安全的SQL查询。通过`cubrid_real_escape_string`函数防止SQL注入,然后执行查询并获取结果。在查询失败时提供错误信息,接着使用`cubrid_fetch_assoc`遍历结果集并打印数据。最后,使用`cubrid_free_result`释放资源。
摘要由CSDN通过智能技术生成

// This is the best way to perform an SQL query

// For more examples, see cubrid_real_escape_string()$query=sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",cubrid_real_escape_string($firstname),cubrid_real_escape_string($lastname));// Perform Query$result=cubrid_query($query);// Check result

// This shows the actual query sent to CUBRID, and the error. Useful for debugging.if (!$result) {$message='Invalid query: '.cubrid_error() ."\n";$message.='Whole query: '.$query;

die($message);

}// Use result

// Attempting to print $result won't allow access to information in the resource

// One of the cubrid result functions must be used

// See also cubrid_result(), cubrid_fetch_array(), cubrid_fetch_row(), etc.while ($row=cubrid_fetch_assoc($result)) {

echo$row['firstname'];

echo$row['lastname'];

echo$row['address'];

echo$row['age'];

}// Free the resources associated with the result set

// This is done automatically at the end of the scriptcubrid_free_result($result);?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值