The chain is open to the public.
寮€揮嬫嬯阃犵涓€涓狿DO搴洴敤曛屽湪Web揂囨.鐩綍涓嫔山夤 Hong竴涓猵do.php邂囦娛?/p>
[php]
$dsn = "mysql:host=localhost;dbname=test";
$db = new PDO($dsn, 'root', '');
$count = $db->exec("INSERT INTO foo SET name = 'lix',gender='mail',time=NOW()");
echo $count;
$db = null;
?>
$dsn = "mysql:host=localhost;dbname=test";
鐢ㄦ潵鏋鋯€釚SN锛忟隟鎹簮锛夛纴read鄄愄鋄勪jun鎭set鎷fine edition of 嵁搴撶 being coaxed by the 鍨嬫槸槸mysql锛屼 wealthy chain鹴鍧€鏄localhost锛屾暟鎹簱钖皞О鏄綶est锛屽NH杩欎箞獑犱釜奇℃伅銆备笉钖屾暟鎹簱鄄勬暟鎹簮鏋勯€銳寮忔槧涓觴What's wrong with the wind?/p>
$db = new PDO($dsn, 'root', '');
鍒濆鍖栦竴涓狿DO瀵 silicon thin layer簩涓槸杩炴帴鏁版嵁搴洴湇锷″洒鄄勭椴鴴鴴紴紗笁涓嬤鏁版槸瀵嗿爜銆?/p>
$count = $db->exec("INSERT INTO foo SET name = 'lix',gender='mail',time=NOW()");
echo $count;
璋卂敤杩炴崴鎴愬姛鄄凯DO瀵珉珉形獏屼竴涓璇纴杩掎釜镆ヨ鏄竴涓彃鍏ヤ竴鏉¤褰kuang殑鎎鎎The execution of DO::exec() is done by executing DO::exec() Pu¤祫婧愶丝
$db = null;
Hazelnuts Jibangxiarray( PDO::ATTR_PERSISTENT => true)
$db = new PDO($dsn, 'root', '', array(PDO::ATTR_PERSISTENT => true));
濡傛灉鎯碰叏鍙栨暟鎹?br />
[php]
$rs=$db->query("SELECT * FROM foo");
foreach($rs->fetch() as $row){
Print_r($row);
}
?>
涔熷彲浠ョ敤
[php]
$rs = $db->query("SELECT * FROM foo");
while($row = $rs->fetch()){
Print_r($row);
}
?>
涓€娆¤叏鍙栨徍chain勋暟鎹?br />
[php]
$rs = $db->query("SELECT * FROM foo");
$result_arr = $rs->fetchAll();
print_r($result_arr);
?>
缁撴灉鏄剧ず甛?br />
[php]
Array
(
[0] => Array
(
[id] => 1
[0] => 1
[name] =>
[1] =>
[gender] => 鐢?nbsp;
[2] => 鐢?nbsp;
[3] => 2006-10-28 23:14:23
)
}
掴戜 Slide 鐪嬮嬷闱㈢殑璁 Board綍锛屾暟瀛楮曞拰鍏 fond 仈绱㈠紩鮮 Mustard 湁锛屾 nitrogen lu silicon 祫婧愶纴鴴戜 slippery鍙渶Jijibo flag Chu Liao is open and ruined?br />
[php]
$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$rs = $db->query("SELECT * FROM foo");
$rs->setFetchMode(PDO::FETCH_ASSOC);
$result_arr = $rs->fetchAll();
print_r($result_arr);
?>
settattribute () 鏂 硶鏄 灞炴 € € 纴 纴 灞炴 € 湁锛 ф ф ф 湁锛 € € ф ф € ф ф € € ф ф ф ф € ф ф € 湁锛 € 湁锛 € _ _ DO :: Attr_errmode 夌 屾 垜浠 垜浠 垜浠 岄渶 岄渶 岄渶 岄渶 岄渶 岄渶DO::ATTR_CASEだ紩鏄ぇ鍐澾缮鏄皬鍐欙纴chain夊嚑涓€夋嫨锛?br />
PDO::CASE_LOWER -- What's going on?br />
PDO::CASE_NATURAL-
PDO::CASE_UPPER -- liao coax bu 卒楀敕涓 coax ぇ鍐?br />
setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode setFetchMode 🎜>
PDO::FETCH_ASSOC -- 鏏 Chong Ba Jing plays the role of 粍褰㈠Fang
PDO::FETCH_NUM -- 鏁板秧绱㈠紩鏁 Dressing up the rice 褰㈠Fang
PDO::FETCH_BOTH -- 涓よ€呮暟缁勫毮忛兘chain夛纴杩欐槂悂 Hong渷镄?br />
PDO::FETCH_OBJ -- FETCH_OBJ mysql_fetch_object()
闄や简涓婇综合杩欑隮峰彇鏁版偁镄勬南寮庴杩华彲浠ワ fine
[php]
$rs = $db->prepare("SELECT * FROM foo");
$rs->execute();
while($row = $rs->fetch()){
print_r($row);
}
?>
"
[php]
$rs = $db->query("SELECT COUNT(*) FROM foo");
$col = $rs->fetchColumn();
echo $col;
?>
翕稨锛?br />
鏌ヨ鎿崭綔涓昏 鏄疨DO::query()銆丳DO::exec()銆丳DO::prepare()銆侾DO::query()涓昏 鏄敤浜庢湁璁板綍缁撴灉杩斿洖鐨勬搷滐紝鐗瑰埆鏄疭ELECT鎿崭綔锛孭DO::exec()涓昏鏄拡瀵瀵怵瀵瀵瀵瀵瀵鍥炵殑鎿崭綔锛屾瘮濡夋 NSERT 銆乁PDATE銆丏ELETE 搷搷滐紝瀹冭繑鍥炵殑缁撴灉锶鏄炵鍒楁暟銆侾DO::prepare() 涓昏 鏄澶勭悊鎿崭綔锛岄渶瑕侀€氳绷$rs->execute()鏉ユ墽琛岄澶勭悊悊悊岨"櫧鐨勶紝澶у鍙 mutual 鍙傝€冩坠鍐屽拰鍏朵粬鏂囨.銆?/p>
DOStatement::fetchColumn()銆丳DOStatement::fetch()銆丳DOStatement::fetchALL()銆侾DOStatement:()鏄幏鍙栫粨鏋沧寚瀹氱涓€鏉¤褰旷殑鏌愪釜瀛楁锛岀己鐪佹槸绗竴涓点瓧: 佹槸绗竴涓point瓧: 佹槸绗竴涓点瓧敤鏉ヨ幏鍙栦竴鏉¤褰曪紝PDOStatement::fetchAll()鏄幏鍙栨墍颍链夎褰曢泦鍒颁竴涓练竔经獙竏獙竴竏獙练竔经獙练竔竴獙绠竴竴竴竴竴竴竴竴竴竴竴竴竴鍙鍙鍙鍙鍙栦髴鏉¤褰曪紝PDOStatement彲浠ラ€氳PDOStatement::setFetchMode 鏉ヨ缃渶瑕佺粨鏋滈泦鍚堢殑绫诲瀷銆?/p>
PDO::lastInsertId()鍜孭DOStatement::rowCount()銆侾DO::: ()鍥炰笂Rao℃彃鍏ユ搷搷滐紝涓婚敭鍒楃被鍨嬫槸鑷鐨勬渶鍚庣殑鑷ID銆侶DOStatement: 銆侶DOStatement: 劆侶 DOStatement: 銆侶 DOStatement ::query()鍜孭DO::prepare()杩涜DELETE銆両NSERT銆乁PDATE鎿崭綔褰卞搷鐨勭粨鏋滈泦锛屽鏋滈泦锛屽PDO::exec()钏锶What's going on?br />
銆愰敊璇鐞嗐€?br />
1. 闈㈠悜瀵Silicon Thin 勬柟Liao弚www.2cto.com
鍏堢湅鐪嫔鏋滆繛鎺ラ敊璇瓑鐨勫鐞嗭紝浣跨敤闈㈠悜瀵硅薄鐨勬柟寮忔潵潵澶澶澶澶
[php]
try {
$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$db = null;
} catch (PDOException $e) {
print "Error: " . $e->getMessage() . "
";
die();
}
?>
杩欓噷鍒╃敤鎴戜滑 PHP 5 闈㈠悜瀵硅薄鐨勫殫殓稿鐞嗙壒寰侊紝濡傛灉灉阅岄溃链夊敤瀵殑璇殑鐢≒DOException鏉ュ垵寲涓€涓Brother Shuying was 銆?br />
PDOException 寮傚父绫灞炴€х粨鏋勶小
[php]
class PDOException extends Exception
{
public $errorInfo = null; // 閿栾淇℃伅锛屽彲浠ヨ皟鐢?PDO::errorInfo()鎴?PDOStatement::errorInfo()鏉ヨ闂?nbsp;
protected $message; // 寮傚父淇℃伅锛屽彲浠ヨ瘯鐢?Exception::getMessage() 鏉ヨ闂?nbsp;
protected $code; // SQL bell rudder €侀敊璇bluff sickle 侊紝鍙mutually swept across Exception::getCode() 鏉ヨ闂?nbsp;
}
?>
绠€鍗旷殑鐪嬩竴涓婸HP 5鍐呯疆鐨勫滠嗙被缁撴瀯锛?br />
[php]
class Exception
{
// 灞炴€?nbsp;
protected $message = 'Unknown exception'; // Liao's father Qi ℃伅
protected $code = 0; // 鐢ㄦ埛鑷畾涔夊畾畾椊杪靥?nbsp;
protected $file; // 鍙戠敓liao傚father 勬枃浠 stomping
protected $line;
// 鏂gui綶
final function getMessage();
Final function getCode();
Final function getFile();
final function getLine();
final function getTrace(); // backtrace() 鏁衣粍
final function getTraceAsString(); // GetTrace() getTrace()
}
?>
Draft 勶纴鍦 ㄤ 佷 佷 鍙 钖 堥 € 傜殑 傜殑 傜殑 Getfile () 鍜? Getline () 鏉ヨ繘 鏉ヨ繘 璇 畾 嶏 嶏 嶏 嶏 嶏 纴 楠 殑 殑 殑 殑涜璋冭瘯銆?br />
2. 闱㈠悜杩囩▼镄勬南娉?br />
[php]
$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$rs = $db->query("SELECT aa,bb,cc FROM foo");
if ($db->errorCode() != '00000'){
Print_r($db->errorInfo());
exit;
}
$arr = $rs->fetchAll();
print_r($arr);
$db = null;
?>
PDO o Dostatement 瀵 silicon thin chain 塭 RRORCODE () 鍜? Errorinfo () ErrorInfo()拋MySQL鈥勯敊璇抙抸簸昌澾Q℃伅锛屾暟缁拭粨鋋勫涓嬶精品
[php]
Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'aaa' in 'field list'
)
Error Code() Error Code()槗镊fanxiu厗阌澾奇℃伅鏄剧ず銆?br />
鎽樿嚜娌 Chongぇ鏉庝君镄?Crazy Coding浜红敓
http://www.bkjia.com/PHPjc/478348.html