PDO connection not able to success

Hi support,

I have just started a free account for testing my web app whether all my basic requirements are full-full or not before going to purchase a Pro account.

So just i have tested my database connection first using the ‘php_pdo_sqlsrv’ driver. But it’s failed. May at your end the latest PDO driver is not available in PHP-Ext folder. My php project version is 7. And in local setup i can successfully connect to my database server bcs i have already configured the Microsoft PHP PDO driver in my XAMP.

Please update the driver, so that necessary checking i can made. Also i have uploaded my index.php. You can also check it my directory.

My domain name is : https://scadalivex.000webhostapp.com/


<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    } catch(PDOException $e) {    
    echo "Connection failed: " . $e->getMessage();
    }
?>

PDO works perfect :slight_smile:

This is not Windows hosting :smiley:

  • localhost is the only hostname you can use
  • remote MYSQL is not available on the free platform

Hi support,

My remote database server is Microsoft SQL serve 2014. So i have used ‘PDO sqlsrv’ driver in my code. What’s wrong i have. You have provided the code for mysql driver. Which is not fullfull my goal. If you already have a APACHE hosting setup, then you must support to the PDO SQLSRV driver.

My code is here. please test it…

<?php
    class Dbh {
        private $servername;
        private $username;
        private $password;
        private $dbname;
        private $charset;

        public function connect() {
            $this->servername = "202.191.213.217";
            $this->username = "operator";
            $this->password = "operator";
            $this->dbname = "master";
            // $this->charset = "utf8mb4";

            try {
                $dsn = "sqlsrv:Server=".$this->servername.";Database=".$this->dbname;
                $pdo = new PDO($dsn, $this->username, $this->password);
                $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                echo "SQL-Svr: Database Connection success. ";
                return $pdo;
            } catch (PDOException $e) {
                die ("Database connection failed. ".$e->getMessage()); 
            }
        }
    }

    // To connect
    $object = new Dbh;
    $object->connect();

?>

You can’t use that IP address you’ve listed.

Hi, thanks fr the reply. Ao what’s the solution then. But using that IP address am able to connect from my laptop over internet. I hv setup the XAMPP in my laptop.

Pls guide me how can i then connect to my Database Server ?

Hi !

If your server is hosted locally on your PC, make sure you forward the port on which your database is operating (on MySQL it is usually 3306) so you can access your database worldwide.

Hi teodor,

Yes my Microsoft SQL server is hosted locally and NAT with a public IP i.e 202.191.213.217.
I make confirmed the Port 1433 is already forwarded for access the database from worldwide.
That’s why am can able to connect the database from world wide, like from my Home Laptop accordingly.

Now thing is that PHP PDO connection not able to connect after hosted in to your webhost account. But PHP PDO works fine from my laptop (my laptop in in internet). Please help me the connection so that i can go to procure your professional plan.

Awaiting your good answer in soon.

Hi Teodor,

Request your kind solution please…!

I have just checked the requirements: and yes, free plans do not support MIcrosoft SQL.

However paid plans do support it. You can enable it from cPanel after you’ve bought one. Hostinger also offers 30-days money back guarantee if you don’t like the service, or if it doesn’t work the way you supposed to:

Hi Tedor,

Am so much appreciated on your confirmation and reply as well. Before i go for purchase, i want to share some thing: i want to purchase a little plan now. If every thing works fine regarding my PDO connection, then i will extend for a long term plan for my company i.e ‘Jindal Steel And Power Limited, India’.

So pls take your valuable time and just make me confirm, in each plan you have 30 day’s money back. So from which plan is best and will definitely success for us to work with the ‘pdo_sqlsvr’ driver communication ?

1: Single shared hosting
2: Premium Shared hosting
3: VPS Server Plan-1

But one thing i make sure, if the PDO works fine then our best preference is VPS server plan with your priority support.

Awaiting your response in soon for go ahead immediately.

Thanks
Bhabani shankar dash

Hi Tedor,

Have a nice day…

Awaiting your valuable reply as per my last mail request.

Thanks
Bhabani

Each plan offers 30-Days money back guarantee. I suggest you to start with a cheap one: Premium Shared hosting. It’s only $3 per 3 months.

If everything works as expected, renew the plan, or move on to an advanced one :slight_smile:

Hi Teodor,

Thanks for your great reply. Have a great day.

After getting permission from my organization, i hv purchased now the Premium shared service with a priority support and a domain as well i.e ‘scadalivex.online’.

Awaiting your good support once again to resolve my current Remote Database Connection issue. As you may know my Remote database is Microsoft SQL Server 2014. Having IP 202.191.213.217. And the credentials and php codes are already i have shared you in before.

Thanks
Bhabani

Hi Teodor,

I have facing the issue after uploaded my PHP file, the error say’s "Database connection failed. SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 13 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 13 for SQL Server …

This is my URL: http://scadalivex.online/dbh.php
Request you to please help me.

This forum is only for free plans support. My attributes don’t extend afterwards.

Since you have bought the premium plan, please login to cpanel.hostinger.com and contact Hostinger Support through their direct chatline and ask them for any issues you may have: