易截截图软件、单文件、免安装、纯绿色、仅160KB

[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();
}
?>


相关文档:

PHP: How to Get the Current Page URL

Sometimes, you might want to get the current page URL that is shown
in the browser URL window. For example if you want to let your visitors
submit a blog post to Digg you need to get that same exact URL. There
are plenty of other reasons as well. Here is how you can do that.
Add the followin ......

PHP 开发编辑工具

强大而且免费的 zend studio 首当其冲,可惜本人机器配置不高,运行起来十分吃力,用没两次太受罪就放弃了。
PHPEdit,短小精悍,可限时试用,感觉一般。
PHPDesigner 正在用,还是可以一试,网上的注册机出的也相当及时。 0.0
纯文本编辑 Editplus 还是常备工具。 ......

PHP 读取地址栏 参数


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 读写文件示例


  PHP 中,数据通常都是存储在MySQL数据库当中的。但是有些时候,我们还是需要使用PHP读写一些本地文件。比如生成静态页面或者数据的本地缓存。
  我们用一个简单的访问日志来演示一下fopen, fread, fwrite, fclose的用法。
  每当我们访问此网页的时候,会显示出访问过的IP以及访问时间;同时当前的访问也会被记 ......

PHP 中长连接的实现

  每次我们访问 PHP 脚本的时候,都是当所有的PHP脚本执行完成后,我们才得到返回结果。如果我们需要一个脚本持续的运行,那么我们就要通过 PHP 长连接的方式,来达到运行目的。
  每个 PHP 脚本都限制了执行时间,所以我们需要通过 set_time_limit 来设置一个脚本的执行时间为无限长;然后使用 flush() 和 ob_flush() ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号