php框架codeigniter数据库操作整理
Tag:
-
1.
$query = $this->db->query('SELECT name, title, email from my_table');
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->email;
}
2.
foreach ($query->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['email'];
}
3.
if ($query->num_rows() > 0)
4.
$query = $this->db->query('SELECT name from my_table LIMIT 1');
$row = $query->row();//$row = $query->row_array();
echo $row->name;
你可以传递参数以便获得某一行的数据。比如我们要获得第 5 行的数据:
$row = $query->row_array(5);
除此以外, 我们还可以使用下面的方法通过游标的方式获取记录:
$row = $query->first_row()
$row = $query->last_row()
$row = $query->next_row()
$row = $query->previous_row()
5.
$sql = "INSERT INTO mytable (title, name)
VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")";
$this->db->query($sql);//$query = $this->db->get('table_name');
echo $this->db->affected_rows();
6.
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);
$this->db->insert('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
7.
$this->db->escape()
8.
$sql = "SELECT * from some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick')); //自动转义
9.
该函数返回当前请求的字段数(列数):
$query = $this->db->query('SELECT * from my_table');
echo $query->num_fields();
10.
$query = $this->db->query('SELECT title from my_table');
foreach ($query->result() as $row)
{
echo $row->title;
}
$query->free_result(); // $query 将不再可用
$query2 = $this->db->query('SELECT name from some_table');
$row = $query2->row();
echo $row->name;
$query2->free_result(); // $query2 将不再可用
11.
$this->db->
相关文档:
原帖地址:http://www.phpma.com/english/20071215/640.html
Description
array explode
( string separator, string string [, int limit])phpma.com
Returns an array of strings, each of which is a substring of string
formed by splitting it on boundaries formed by the string separator
. If limit
is ......
编译安装php5.2.0时出错解决方案
1.错误信息...................如下
checking for mcrypt support... no
checking for mhash support... no
checking whether to include mime_magic support... no
checking for MING support... no
checking for mSQL support... no
checking for MSSQL support via FreeTDS ......
<html>
<head><title>文件上传</title></head>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFCC">
<?php
if(!$_POST['upload'])
{
?>
<form enctype="multipart/form-data" action="upload.php" method="post"& ......
php特殊字符过滤
1、过滤标签(HTML):strip_tags()
例如:
<?php
$text = '<?php ?><p>Test paragraph.</p><!-- Comment -
-> <a href=http://topic.csdn.net/u/20090311/09/"#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// 允许使用<p>和< ......