在php中连接数据库 pdo

时间:2019-11-27
本文章向大家介绍在php中连接数据库 pdo,主要包括在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());
    }

原文地址:https://www.cnblogs.com/lz0925/p/11943770.html