[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();
}
?>
相关文档:
定义和用法
htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。
预定义的字符是:
& (和号) 成为 &
" (双引号) 成为 "
' (单引号) 成为 '
< (小于) 成为 <
> (大于) 成为 >
语法
htmlspecialchars(string,quotestyle,character-se ......
PHP中的变量也有访问域。作用域可以使用PHP中global
在函数内部、对象中和类中定义的局部变量在函数外部是无法被访问到的;同理,在函数外部、对象外和类外定义的变量,如果没有被传入,也是无法被访问到的。
但是如果一个很多变量要同时被传入很多函数、对象或者类,我们也可以直接将其全局化。这样不仅可以 ......
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type = "text/css">
&nbs ......
每次我们访问 PHP 脚本的时候,都是当所有的PHP脚本执行完成后,我们才得到返回结果。如果我们需要一个脚本持续的运行,那么我们就要通过 PHP 长连接的方式,来达到运行目的。
每个 PHP 脚本都限制了执行时间,所以我们需要通过 set_time_limit 来设置一个脚本的执行时间为无限长;然后使用 flush() 和 ob_flush() ......