sql server - Issue with connection to MSSQL from PHP -


i'm having problems putting data mssql php - error:

sqlsrv_query() expects parameter 1 resource, boolean given in [path] on line 13

i can't see problem is, or if have syntax error.

<?php     $host = "127.0.0.1";      $dbusername = "humid";      $dbpassword = "humid";       $db = "test";     $t = $_get['t'];     $h = $_get['h'];       $connectioninfo = array("uid" => $dbusername, "pwd" => $dbpassword, "database" => $db) or die("couldnt connect server");     $dbconnect = sqlsrv_connect($host, $connectioninfo);     $sql = "insert historic values(null,$t,$h,current_timestamp)";     sqlsrv_query($dbconnect, $sql); ?> 

any appreciated! i'm not familiar mssql, mysql


okay, i've enabled error messages, , i've got 1 now:

array ( [0] => array ( [0] => 42000 [sqlstate] => 42000 [1] => 126 [code] => 126 [2] => [microsoft][odbc driver 11 sql server][sql server]invalid pseudocolumn "$t". [message] => [microsoft][odbc driver 11 sql server][sql server]invalid pseudocolumn "$t". ) )

however, have no idea be? because $t sql syntax don't know of? long story short, i'm building temp , humid logging device arduino, , need post values db (using php) - syntax php looks this:

test.php?t=1&h=2

what have done wrong now? when testing on mysql server private, worked fine >_<

-- edit, solution found! --

okay, found solution, i'm not sure if of other answers had direct fix, however. mssql apparently doesn't accept "null" mysql does. ofc. last thing edited, i'm not sure if there errors in prior code. hoever, below final (and working) code. arduino posts , everything. eureka!

<?php     $host = "wdkto560\test";      $dbusername = "humid";      $dbpassword = "humid";       $db = "test";     $t = $_get['t'];     $h = $_get['h'];        $connectioninfo = array("uid" => $dbusername, "pwd" => $dbpassword, "database" => $db) or die("couldnt connect server");     $dbconnect = sqlsrv_connect($host, $connectioninfo);     $sql = "insert historic (temperature, humidity, date) values($t,$h,current_timestamp)";     sqlsrv_query($dbconnect, $sql) or die( print_r( sqlsrv_errors(), true)); ?> 

sqlsrv_connect() failing connection , returning false. have debug it.

  1. check if database , username correct .
  2. user has access permission write database
  3. you have installed mssql driver php.

hope helps.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -