Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to connect database using PDO in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 571
    Comment on it

    PDO does not account for database specific syntax. It can allow for the process of switching databases and platforms. PDO can simply switch the connection string in many instances.

    PDO supports the following database:

    PDO_FIREBIRD ( Firebird/Interbase 6 )
    PDO_DBLIB ( FreeTDS / Microsoft SQL Server / Sybase )
    PDO_IBM ( IBM DB2 )
    PDO_INFORMIX ( IBM Informix Dynamic Server )
    PDO_MYSQL ( MySQL 3.x/4.x/5.x )
    PDO_OCI ( Oracle Call Interface )
    PDO_ODBC ( ODBC v3 (IBM DB2, unixODBC and win32 ODBC) )
    PDO_PGSQL ( PostgreSQL )
    PDO_SQLITE ( SQLite 3 and SQLite 2 )
    PDO_4D ( 4D )

    Database connection string for some databases:

    $servername = "localhost"; $username = "username"; $password = "password"; try { $DBH = new PDO("mssql:host=$host;dbname=$dbname, $user, $pass"); $DBH = new PDO("sybase:host=$host;dbname=$dbname, $user, $pass"); # MySQL with PDO_MYSQL $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); # SQLite Database $DBH = new PDO("sqlite:my/database/path/database.db"); // set the PDO error mode to exception $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: