如果发生Call to undefined function mysql_connect()这种错误,linux下则yum install -y php-mysql然后php.ini中增加extension=mysql.so, 重启httpd即可。
---> php-mysqlB.x86_64 : 一个用于使用 MySQL 数据库的 PHP 程序的模块。
1、db_connect.php供include或require
<?php
$host='172.172.172.172';
$user='root';
$passwd='xxx';
$database='xxx';
$db_connect=mysql_connect($host, $user, $passwd) or die(mysql_error());
mysql_select_db($database, $db_connect) or die ('Can\'t use xxx : ' . mysql_error());
?> |
2、mysql_fetch_object,将从mysql的结果集赋给object
$sql_select = "select owner,count(ip) count_ip,reason from filter group by owner order by count_ip desc;";
$query = mysql_query($sql_select) or die("Invalid query: " . mysql_error());
while ($row = mysql_fetch_object($query))
{
$owner = $row->owner;
$count_ip = $row->count_ip;
$reason = $row->reason;
...
} |
3、mysql_fetch_array() 这个函数只是从记录集中取一条记录并赋值给一个数组,然后指针移到下一条记录。不是把整个结果集都直接赋值到一个二维数组。
阅读(1361) | 评论(0) | 转发(0) |