INSERT INTO msg(title,contents,dates) VALUES ($title,$cons,now())
成都網(wǎng)站建設、成都做網(wǎng)站的關注點不是能為您做些什么網(wǎng)站,而是怎么做網(wǎng)站,有沒有做好網(wǎng)站,給創(chuàng)新互聯(lián)建站一個展示的機會來證明自己,這并不會花費您太多時間,或許會給您帶來新的靈感和驚喜。面向用戶友好,注重用戶體驗,一切以用戶為中心。
將字段名兩邊的單引號去掉就沒問題了,親測成功!希望能幫到你。
本文實例講述了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相關內(nèi)容感興趣的讀者可查看本站專題:《PHP基于pdo操作數(shù)據(jù)庫技巧總結(jié)》、《php+mysqli數(shù)據(jù)庫程序設計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
您可能感興趣的文章:關于php連接mssql:pdo
odbc
sql
serverPHP5中使用PDO連接數(shù)據(jù)庫的方法PHP中PDO連接數(shù)據(jù)庫中各種DNS設置方法小結(jié)ThinkPHP框架基于PDO方式連接數(shù)據(jù)庫操作示例PHP使用ODBC連接數(shù)據(jù)庫的方法tp5(thinkPHP5)框架連接數(shù)據(jù)庫的方法示例PHP7使用ODBC連接SQL
Server2008
R2數(shù)據(jù)庫示例【基于thinkPHP5.1框架】tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫的方法thinkPHP5實現(xiàn)數(shù)據(jù)庫添加內(nèi)容的方法tp5(thinkPHP5)框架數(shù)據(jù)庫Db增刪改查常見操作總結(jié)PHP利用pdo_odbc實現(xiàn)連接數(shù)據(jù)庫示例【基于ThinkPHP5.1搭建的項目】
PHP框架 Laravel Eloquent ORM 批量插入數(shù)據(jù)是通過傳入數(shù)組實現(xiàn)的。
比如:
DB::table('users')-insert(array(
array('email' = 'taylor@example.com', 'votes' = 0),
array('email' = 'dayle@example.com', 'votes' = 0),
));
以上是操作表users,執(zhí)行insert語句,參數(shù)是一個數(shù)組,封裝了兩條數(shù)據(jù),這里可以自定義數(shù)據(jù),insert內(nèi)部就編程批量插入了。
然后調(diào)用save方法:
public static function create(array $attributes)
{
$model = new static($attributes);
$model-save();
return $model;
}
當前文章:php原生插入數(shù)據(jù) php導入
URL分享:http://muchs.cn/article24/hjsdce.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供域名注冊、網(wǎng)站設計公司、標簽優(yōu)化、品牌網(wǎng)站建設、定制網(wǎng)站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)