欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實現(xiàn)的pdo連接數(shù)據(jù)庫并插入數(shù)據(jù)功能簡單示例

 更新時間:2019年03月30日 00:36:22   作者:TANKING-  
這篇文章主要介紹了PHP實現(xiàn)的pdo連接數(shù)據(jù)庫并插入數(shù)據(jù)功能,結合簡單示例形式分析了pdo數(shù)據(jù)庫連接及執(zhí)行基本的插入SQL語句相關操作技巧,需要的朋友可以參考下

本文實例講述了PHP實現(xiàn)的pdo連接數(shù)據(jù)庫并插入數(shù)據(jù)功能。分享給大家供大家參考,具體如下:

創(chuàng)建配置文件

pdo_config.php

<?php
$db_Type = "mysql";//數(shù)據(jù)庫類型
$host = "localhost";//主機名
$dbName = "test";//數(shù)據(jù)庫名
$userName = "root";//用戶名
$password = "root";//密碼
$dsn = "{$db_Type}:host={$host};dbname={$dbName}";
?>

pdo插入數(shù)據(jù)庫

pdo_insert.php

<?php
header('Content-type:text/html; charset=utf-8');
require 'pdo_config.php';
try{
    $pdo = new PDO ($dsn,$userName,$password);//創(chuàng)建一個連接對象
    $pdo->exec('set names utf8');//設置編碼
    $sql = "INSERT student (name,email) VALUES ('李四','123@qq.com')";
    $pdo->exec($sql);
}catch (PDOException $e){
    die('操作失敗'.$e->getMessage());
}
//關閉連接
$pdo = null;
?>

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP基于pdo操作數(shù)據(jù)庫技巧總結》、《php+mysqli數(shù)據(jù)庫程序設計技巧總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論