|
操作系统:Fedora 21 PHP版本:最新的5.6.9 开发工具:gedit
|
|
本帖负责收集笔记。
|
|
<?php include_once("conn.php"); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>PDO Learning</title> </head> <body> <?php ?> </body> </html>
最基本的HTML5页面代码,好难记。。。
|
|
回复:3楼 不过也比HTML4好记多了。 HTML4一上来就是: <!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
首先,连接数据库。 $db = new PDO("mysql:host=localhost;dbname=test", "php", "it"); 密码先填写一个错误的,提示:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [1045] Access denied for user 'php'@'localhost' (using
password: YES)' in /var/www/html/temp/11330/conn.php:4
Stack trace:
#0 /var/www/html/temp/11330/conn.php(4):
PDO->__construct('mysql:host=loca...', 'php', 'it')
#1 /var/www/html/temp/11330/index.php(2):
include_once('/var/www/html/t...')
#2 {main}
thrown in /var/www/html/temp/11330/conn.php on line 4
所以必须要加try-catch块来处理这个错误
|
|
|
|
function display_exception($msg) { echo $msg; } set_exception_handler("display_exception"); $db = new PDO("mysql:host=localhost;dbname=test", "php", "it");
exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access
denied for user 'php'@'localhost' (using password: YES)' in
/var/www/html/temp/11330/conn.php:8
Stack trace:
#0 /var/www/html/temp/11330/conn.php(8):
PDO->__construct('mysql:host=loca...', 'php', 'it')
#1 /var/www/html/temp/11330/index.php(2):
include_once('/var/www/html/t...')
#2 {main}
|
|
try { $db = new PDO("mysql:host=localhost;dbname=test", "php", "it"); } catch (PDOException $e) { echo $e->getMessage(); }
SQLSTATE[HY000] [1045] Access denied for user 'php'@'localhost' (using password: YES)
|
|
try { $db = new PDO("mysql:host=localhost;dbname=test", "php", "it"); } catch (PDOException $e) { trigger_error("Failed connecting to the database server.", E_USER_ERROR); }
Fatal error: Failed connecting to the database server. in /var/www/html/temp/11330/conn.php on line 7
|
|
10樓 張樹人
2015-5-30 19:39
回复:3楼 标准的写法是“<!DOCTYPE html>” “DOCTYPE”是大写
|