Home > php教程 > php手册 > body text

一些关于PHP的知识

WBOY
Release: 2016-06-13 12:36:12
Original
894 people have browsed it

1、如何配置PhpMyAdmin2.9
网络上很多教程的配置文件是针对PhpMyAdmin底版本的,一开始连2.9配置文件都不知道放哪里?
配置文件相对地址是:config.sample.inc.php  (不是这个libraries/config.default.inc.php)

2、让phpMyAdmin使用密码登陆
在设置config.inc.php设置以下参数:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['blowfish_secret'] = '123456'; // 随便设置一个非空字符串
$cfg['DefaultLang'] = 'zh'; // 默认显示中文,可选

3、没有发现 PHP 的扩展设置mbstring, 而当前系统好像在使用宽字符集。没有 mbstring....修改php.ini 文件extension=php_mbsting.dll 要重起才能生效!

4、php读取mysql数据库中文字符的时候全部显示问号?
在查询数据库之前,先使用mysql_query("set names 'gb2312'");

5、用PHP输出静态页面

有2种

一种是利用模板技术,另一种是用ob系列函数。两种方法,看起来都差不多,但是实际上,却是不同的。

第一种:利用模板

目前PHP的模板可以说是很多了,有功能强大的smarty,还有简单易用的smarttemplate等。

它们每一种模板,都有一个获取输出内容的函数。

我们生成静态页面的方法,就是利用了这个函数。

用这个方法的优点是,代码比较清晰,可读性好。

这里我用smarty做例子,说明如何生成静态页

require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//这里的 fetch() 就是获取输出内容的函数,现在$content变量里面,就是要显示的内容了
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?> 

第二种方法:利用ob系列的函数

这里用到的函数主要是 ob_start(), ob_end_flush(), ob_get_content(),

其中ob_start()是打开浏览器缓冲区的意思,

打开缓冲后,所有来自PHP程序的非文件头信息均不会发送,

而是保存在内部缓冲区,直到你使用了ob_end_flush().

而这里最重要的一个函数,就是ob_get_contents(),

这个函数的作用是获取缓冲区的内容,相当于上面的那个fetch(),

道理一样的。代码:

ob_start();
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
6、PHP语言读取数据库详解
这段代码的功能是:

连接到一个 url 地址为localhost 、 端口为 3306 的mysql服务器上。mysql服务器的帐号是"root",密码是"9999"。mysql 服务器上有一个数据库 ok , 数据库里有一个表 abc。表 abc 一共为两列,列名分别是 "id" 和 "name" ,将 abc 里的所有数据读出来。



$dbh = @mysql_connect("localhost:3306","root","9999");

/* 定义变量dbh , mysql_connect()函数的意思是连接mysql数据库, "@"的意思是屏蔽报错 */

if(!$dbh){die("error");}

/* die()函数的意思是将括号里的字串送到浏览器并中断PHP程式 (Script)。括号里的参数为欲送出的字串。 */

@mysql_select_db("ok", $dbh);

/* 选择mysql服务器里的一个数据库,这里选的数据库名为 ok */

$q = "Select * FROM abc";

/* 定义变量q, "Select * FROM abc"是一个SQL语句,意思是读取表abc中的数据 */

?>









$rs = mysql_query($q, $dbh);

/* 定义变量 rs ,函数mysql_query()的意思是:送出 query 字串供 MySQL 做相关的处理或者执行.由于php是从右往左执行的,所以,rs的值是服务器运行mysql_query()函数后返回的值 */

if(!$rs){die("Valid result!");}

echo "

";

echo "";

while($row = mysql_fetch_row($rs)) echo "";

/* 定义量变(数组)row,并利用while循环,把数据一一写出来. 
函数mysql_fetch_row()的意思是:将查询结果$rs单列拆到阵列变数中. 
$row[0] 和 $row[1] 的位置可以换*/

echo "
ID Name
$row[0] $row[1]
";

?>









$rs = mysql_query($q, $dbh);

while($row = mysql_fetch_object($rs)) echo "$row->id $row->name 
";

/* id和name可以换位置 */

?>









$rs = mysql_query($q, $dbh);

while($row = mysql_fetch_array($rs)) echo "$row[id] $row[name] 
";

/* id和name可以换位置 */

?>





@mysql_close($dbh);

/* 关闭到mysql数据库的连接 */

?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!