|
操作系統: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」是大寫
|