skip to Main Content

My current Website Control Panel is PLESK Parallels, and i’m trying to use PDO MSSQL on my website.

I’ve searched the internet and i’m aware that the PDO dll needs to be in my php.ini file and such, but I keep reading different ways to do it all the time, using commands like YUM and i’m getting confused.

Can someone possibly, in plain, simple black and white instructions, explain the process so I can simply run code like this

try {
$hostname = "myhostname";
$port = myportnumber;
$dbname = "databasename";
$username = "user";
$pw = "password";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "n";
exit;
}

When I load my page where this command is located i get the error message

‘Failed to get DB handle: could not find driver’

Thanks

2

Answers


  1. Example of installing pdo_dblib on CentOS-like OS for Plesk PHP 5.6:

    # yum install plesk-php56-devel
    # /opt/plesk/php/5.6/bin/pecl download pdo_dblib
    # tar -xzf PDO_DBLIB-1.0.tgz
    # cd PDO_DBLIB-1.0/
    # /opt/plesk/php/5.6/bin/phpize
    # ./configure --with-php-config=/opt/plesk/php/5.6/bin/php-config --with-pdo-dblib=./freetds
    
    # vim pdo_dblib.c
    

    On line #37 replace:

    function_entry pdo_dblib_functions[] = {
    

    with:

    zend_function_entry pdo_dblib_functions[] = {
    

    Save file and:

    # make
    # make install
    

    you should see something like

    Installing shared extensions:     /opt/plesk/php/5.6/lib64/php/modules/
    

    Enable extension:

    # echo "extension=pdo_dblib.so" >> /opt/plesk/php/5.6/etc/php.d/pdo_dblib.ini
    

    Verify:

    # /opt/plesk/php/5.6/bin/php -m | grep pdo_dblib
    pdo_dblib
    

    Now sites in Plesk with PHP handler 5.6 will work with:

    $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
    

    Pay attention for :

    Login or Signup to reply.
  2. PHP PDO works in OOPS .

    Hence in PHP PDO first you must create a database handler using PDO class which is already defined in PHP Library. which will work as object for your database queries.

    When you connect your database using PDO Class than you are ready to play with your queries with the database handler which you got during PDO connection.

    $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
    

    Here $dbh will works as database handler object for MySQL Queries Operations.

    I have a personal blog for PHP PDO here . Just go to reference and take a look how queries are working . Finally i would like to say it’s very simple and secure.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search