API with SLIM PHP in LAMP Server with MSSQL database -


i have lamp server in ubuntu. worked on api's using slim framework , mysql database , working fine. problem cant connect api mssql. install freetds in ubuntu include in freetds.conf

 [myserver]     host = myhost     port = myport 

here's connection:

function getconnection() {    $dbhost="myserver.database.windows.net";    $dbuser="user";    $dbpass="mypass";    $dbname="mydb";    $dbh = new pdo("dblib:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);      $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception);    return $dbh; } 

here's api in slim:

$app = new slim\app();  $app->get('/clients', 'getclients');   $app->run();  function getclients() { $sql = "select * mytable";  try {     $db = getconnection();     $stmt = $db->query($sql);       $clients = $stmt->fetchall(pdo::fetch_obj);     $db = null;     echo '{"client": ' . json_encode($clients) . '}'; } catch(pdoexception $e) {     echo '{"error":{"text":'. $e->getmessage() .'}}';  } } 

i think missing something....

i think need let pdo know port

http://php.net/manual/en/ref.pdo-dblib.php

$hostname = "myhost"; $port = 10060; $dbname = "tempdb"; $username = "dbuser"; $pw = "password"; $dbh = new pdo ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw"); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -