[PHP]PDO的使用
1. 安装php5.1以上的版本,有支持pdo!为了使你的环境能提供对pdo的支持!在php.ini文件加入以下:
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_pdo_mssql.dll(支持mssql数据库)
2. 以下为PH中PDO的具体使用
<?php
$dsn = 'mysql:dbname=MyDbName;host=localhost';
$user = 'root';
$password = '666666';
try {
$dbCon = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print 'Connection failed: '.$e->getMessage();
}
//------------pdo query example---------
$strSQL = "select * from Users";
//---------method1---------
try {
$result = $dbCon->query($strSQL);
if( $result ){
$uCol = $result ->columnCount();
$arRS = $result ->fetchAll();
foreach ($arRS as $row){
for( $i=0; $i<$uCol; $i++ )
print $row[$i]." ";
print "<br>";
}
}
}catch (PDOException $e) {
print $e->getMessage();
}
//---------method2---------
try {
$sth = $dbCon->prepare($strSQL);
$sth->execute();
$uCol = $sth->columnCount();
while($row = $sth->fetch()){
for( $i=0; $i<$uCol; $i++ )
print $row[$i]." ";
print "<br>";
}
$result = $sth->fetchAll();
foreach ($result as $row){
for( $i=0; $i<$uCol; $i++ )
print $row[$i]." ";
print "<br>";
}
}catch (PDOException $e) {
print $e->getMessage();
}
?>
相关文档:
用Ajax实现Tab效果的
先创建
ajax.php,在其中输入如下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample 2_1</title>
<me ......
1. $_GET
:
http://localhost/a.php?a=ok
<?
echo
$_GET['a']; //显示"ok"
?>
2. $_SERVER['QUERY_STRING']
http://localhost/a.php?a=1&b=2&c=3
......
PHP 中,数据通常都是存储在MySQL数据库当中的。但是有些时候,我们还是需要使用PHP读写一些本地文件。比如生成静态页面或者数据的本地缓存。
我们用一个简单的访问日志来演示一下fopen, fread, fwrite, fclose的用法。
每当我们访问此网页的时候,会显示出访问过的IP以及访问时间;同时当前的访问也会被记 ......
为了脚本程序的兼容性,很多时候脚本的名称都不是固定的。所以我们需要通过动态获取当前脚本的路径、文件名来完成某些功能。
PHP 中,我们可以使用常量 __FILE__ 来获取当前被执行脚本的完整路径。
注意:当包含此变量的脚本被其他脚本include或者require的时候, __FILE__ 将仍然返回此脚本的地址,而不是 ......