在php中连接数据库 pdo
在php中连接数据库 pdo
//数据库信息
$mysql_conf = array(
'host' => '127.0.0.1',
'db' => 'meteorolog_foreign',
'db_user' => 'root',
'db_pwd' => '123456',
);
try {
//创建一个pdo对象
$pdo = new PDO("mysql:host=" . $mysql_conf['host'] . ";dbname=" . $mysql_conf['db'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
//设置编码
$pdo->exec('set names utf8');
$sql1 = "INSERT INTO me_ir_api_log (name,method,param,server,client,create_time,start_time) VALUES";
$sql1 .= "('$name','$method','$param_json','$server','$client','$create_time','$start_time')";
$res1 = $pdo->exec($sql1);
}catch (PDOException $e){
die('操作失败'.$e->getMessage());
}
知止而后有定,定而后能静,静而后能安,安而后能虑,虑而后能得。
所谓诚其意者,毋自欺也。