今回は、PDO を拡張して PostgreSQL オブジェクト リレーショナル データベースに接続する手順について詳しく説明します。 PDO を拡張して PostgreSQL オブジェクト リレーショナル データベースに接続する場合の 注意事項 は次のとおりです。見てみましょう。 $pdo = NULL;
if(version_compare(PHP_VERSION, '5.3.6', ''SET NAMES \'UTF8\'' ));
}
else{
$pdo = new \PDO('pgsql:host=127.0.0.1;port=5432;dbname=postgredb1','postgres',"123456");
}
try {
$pdo->beginTransaction();
$tableName = 'user';
if($fetch = true){
$myPDOStatement = $pdo->prepare("SELECT * FROM " . $tableName . " WHERE id=:id ");
if(!$myPDOStatement) {
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$id = 1;
$myPDOStatement->bindParam(":id",$id);
$myPDOStatement->execute();
if($myPDOStatement->errorCode()>0){
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$item = $myPDOStatement->fetch();
print_r($item);
}
$insertedId = 0;
if($insert = true){
$myPDOStatement = $pdo->prepare("INSERT INTO " . $tableName . "(username,password,status) VALUES(:username,:password,:status)");
if(!$myPDOStatement) {
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$timestamp = time();
$data = array(
'username' =>'usernamex',
'password' =>'passwordx',
'status' =>'1',
);
$myPDOStatement->bindParam(":username",$data['username']);
$myPDOStatement->bindParam(":password",$data['password']);
$myPDOStatement->bindParam(":status",$data['status']);
$myPDOStatement->execute();
if($myPDOStatement->errorCode()>0){
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$affectRowCount = $myPDOStatement->rowCount();
if($affectRowCount>0){
$insertedId = $pdo->lastInsertId();
}
print_r('$insertedId = '.$insertedId);//PostgreSQL不支持
print_r('$affectRowCount = '.$affectRowCount);
}
if($update = true){
$myPDOStatement = $pdo->prepare("UPDATE " . $tableName . " SET username=:username, status=:status WHERE id=:id");
if(!$myPDOStatement) {
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$id = 1;
$username = 'username update';
$status = 0;
$myPDOStatement->bindParam(":id",$id);
$myPDOStatement->bindParam(":username",$username);
$myPDOStatement->bindParam(":status",$status);
$myPDOStatement->execute();
if($myPDOStatement->errorCode()>0){
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$affectRowCount = $myPDOStatement->rowCount();
print_r('$affectRowCount = '.$affectRowCount);
}
if($fetchAll = true){
$myPDOStatement = $pdo->prepare("SELECT * FROM " . $tableName ." WHERE id > :id");
if(!$myPDOStatement) {
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$id = 0;
$myPDOStatement->bindParam(":id",$id);
$myPDOStatement->execute();
if($myPDOStatement->errorCode()>0){
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$list = $myPDOStatement->fetchAll();
print_r($list);
}
if($update = true){
$myPDOStatement = $pdo->prepare("DELETE FROM " . $tableName . " WHERE id=:id");
if(!$myPDOStatement) {
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
//$insertedId = 10;
$myPDOStatement->bindParam(":id",$insertedId);
$myPDOStatement->execute();
if($myPDOStatement->errorCode()>0){
$errorInfo = $myPDOStatement->errorInfo();
throw new \Exception($errorInfo[0].'###'.$errorInfo[1].'###'.$errorInfo[2]);
}
$affectRowCount = $myPDOStatement->rowCount();
print_r('$affectRowCount = '.$affectRowCount);
}
$pdo->commit();
} catch (\Exception $e) {
$pdo->rollBack();
// print_r($e);
}
$pdo = null;
この記事の事例を読んだ後は、この方法を習得したと思います。さらに興味深い情報については、php 中国語 Web サイトの他の関連記事に注目してください。
推奨読書:
PHPテンプレートメソッドパターンの使用の詳細な説明PHPで関数パラメータを動的に取得する手順の詳細な説明以上がPDO 拡張機能を PostgreSQL オブジェクト リレーショナル データベースに接続する手順の詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

phpssionscanStorestrings、numbers、arrays、andobjects.1.strings:textdatalikeusernames.2.numbers:integersorfloatsforcounters.3.arrays:listslikeshoppingcarts.4.objects:complextructuresthataresialized。

tostartaphpsession、outsession_start()atthescript'sbeginning.1)placeitbe foreanyouttosetthesscookie.2)usesionsionsionsionserdatalikelogintatussorshoppingcarts.3)再生セッションインドストップレベントフィックスアタック

セッション再生とは、新しいセッションIDを生成し、セッション固定攻撃の場合にユーザーが機密操作を実行するときに古いIDを無効にすることを指します。実装の手順には次のものが含まれます。1。感度操作を検出、2。新しいセッションIDを生成する、3。古いセッションIDを破壊し、4。ユーザー側のセッション情報を更新します。

PHPセッションは、アプリケーションのパフォーマンスに大きな影響を与えます。最適化方法には以下が含まれます。1。データベースを使用してセッションデータを保存して応答速度を向上させます。 2。セッションデータの使用を削減し、必要な情報のみを保存します。 3.非ブロッキングセッションプロセッサを使用して、同時実行機能を改善します。 4.セッションの有効期限を調整して、ユーザーエクスペリエンスとサーバーの負担のバランスを取ります。 5.永続的なセッションを使用して、データの読み取り時間と書き込み時間を減らします。

phpsesionsareserver-side、whilecookiesareclient-side.1)Sessionsionsionsoredataontheserver、aremoresecure.2)cookiesstoredataontheclient、cookiestoresecure、andlimitedinsizeisize.sesionsionsionivationivationivationivationivationivationivationivate

phpidentifiesauser'ssessionsingsinssessionCookiesIds.1)whensession_start()iscalled、phpgeneratesauniquesidstoredsored incoookienadphpsessidontheuser'sbrowser.2)thisidallowsphptortorieSessiondatadata fromthata

PHPセッションのセキュリティは、次の測定を通じて達成できます。1。session_regenerate_id()を使用して、ユーザーがログインまたは重要な操作である場合にセッションIDを再生します。 2. HTTPSプロトコルを介して送信セッションIDを暗号化します。 3。Session_Save_Path()を使用して、セッションデータを保存し、権限を正しく設定するためのSecure Directoryを指定します。

phpsessionFilesToredInthededirectoryspecifiedBysession.save_path、通常/tmponunix-likesystemsorc:\ windows \ temponwindows.tocustomizethis:1)uesession_save_path()tosetaCustomdirectory、ensuringit'swritadistradistradistradistradistra


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 中国語版
中国語版、とても使いやすい

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

ドリームウィーバー CS6
ビジュアル Web 開発ツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ホットトピック









