在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());
    }
posted @ 2019-11-27 17:14  _Eternity味道  Views(147)  Comments(0Edit  收藏  举报