Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all 163 articles
Browse latest View live

cannot get my PHP app to connect to sql server

$
0
0

Hello, I have been trying to get my application to connect to sql server v17, while developing in Visual Studio 2017.  When I run my application this is the error I get:

Error connecting to SQL ServerPDOException: could not find driver in C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\model\database.php:4 Stack trace: #0 C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\model\database.php(4): PDO->__construct('sqlsrv:Server=c...', NULL, NULL) #1 C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\index.php(3): require('C:\\Users\\v-data...') #2 {main}

when I run phpinfo() I do not see any references anywhere to MSSQL. 

Also my phpinfo() shows I have php version 7.1.19

This is where the php.ini file that is being loaded it

Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Program Files (x86)\IIS Express\PHP\v7.1\php.ini

and this is how my php.ini file has been edited

[MSSQL]
mssql.allow_persistent=On
mssql.max_persistent=-1
mssql.max_links=-1
mssql.min_error_severity=10
mssql.min_message_severity=10
mssql.compatability_mode=Off
mssql.secure_connection=Off
zend_extension = C:\Program Files (x86)\iis express\PHP\v7.1\ext\php_xdebug.dll
;zend_extension = C:\xampp\php\ext\php_xdebug-2.6.1-7.2-vc15.dll
extension_dir="C:\Program Files (x86)\iis express\PHP\v7.1\ext\"
extension=php_pdo_sqlsrv_71_nts.dll
extension=php_sqlsrv_71_nts.dll

I downloaded the drivers from https://github.com/Microsoft/msphpsql and put them in C:\Program Files (x86)\iis express\PHP\v7.1\ext\

any help or ideas would be appreciated this is the first time I am trying to develop a PHP app in VS with sql server


SQL Server 2016 VMWare Windows 16 64bit - setup Oracle Driver

$
0
0

Hi,

New VMWare SQL Server 2016 Windows 16 64bit - setup Oracle Driver

Where can I find the Oracle driver for SQL2016?

How would I go about installing?

Please Help

Regards

Insert JSON records into SQL Server table using PHP

$
0
0

I hope this is the correct forum for PHP questions related to sql server.

I would like to pull data for all the cities in my county from the census API into a table in sql server.  I have been working on the code and was successful in having it write a record to the database table for the total number of items in the array returned by the API, unfortunately, they are all blank records.

The code below is what i was trying to do, and below this code block is a functional sample someone put together where it treats the JSON as a string, whereas I am thinking in the context of discrete records and fields in a table.  I can follow the concept of the working code, but as I am from a SQL server background, I could relate to it better in the latter form.

Thanks.

<html><head></head><body><?php $serverName = "server"; $connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password" ); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn ) { echo "Connection established. <br /> <br />"; }else{ echo "Connection could not be established. <br /> <br />"; die( print_r( sqlsrv_errors(), true)); } $homepage = file_get_contents("https://api.census.gov/data/2020/dec/responserate?get=NAME,DRRALL,CRRINT,RESP_DATE,CRRALL,GEO_ID,DRRINT&for=place:*&in=state:13"); $content = json_decode($homepage, true); $totalrecords = count($content)."<br /> <br />"; $NAME = $content['NAME']; $DRRALL = $content['DRRALL']; $CRRINT = $content['CRRINT']; $RESP_DATE = $content['RESP_DATE']; $CRRALL = $content['CRRALL']; $GEO_ID = $content['GEO_ID']; $DRRINT = $content['DRRINT']; $state = $content['state']; $place = $content['place']; $trunc = "TRUNCATE TABLE edtable.dbo.Demog_CensusResponse_Test"; $stmt2 = sqlsrv_query( $conn, $trunc ); //foreach ($content as $contentvalue) { for ($x = 1; $x <= $totalrecords; $x++) { //Create SQL query $sql = "INSERT INTO edtables.dbo.Demog_CensusResponse_Test(NAME, DRRALL, CRRINT, RESP_DATE, CRRALL, GEO_ID, DRRINT, state, place) VALUES('$NAME', '$DRRALL', '$CRRINT', '$RESP_DATE', '$CRRALL', '$GEO_ID', '$DRRINT', '$state', '$place')"; //WHERE $place LIKE '42425'"; //Execute SQL query $stmt = sqlsrv_query( $conn, $sql ); if( $stmt === false ){ echo "Something went wrong with the query, check error below <br /> <br />"; die( print_r( sqlsrv_errors(), true)); } else { echo "Statement executed <br /> <br />"; } } //} sqlsrv_free_stmt( $stmt ); sqlsrv_close( $conn ); ?></body></html>

<html><head></head><body><?php $serverName = "server"; $connectionInfo = array( "Database"=>"database", "UID"=>"username", "PWD"=>"password" ); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn ) { echo "Connection established.<br>"; }else{ echo "Connection could not be established.<br>"; die( print_r( sqlsrv_errors(), true)); } //Remove all previous data from the table $deleteRecords_query = "TRUNCATE TABLE edtables.dbo.Demog_CensusResponse_GACities_2020"; $stmt = sqlsrv_query( $conn, $deleteRecords_query); if( $stmt === false ){ die( print_r( sqlsrv_errors(), true)); } $homepage = file_get_contents("https://api.census.gov/data/2020/dec/responserate?get=NAME,DRRALL,CRRINT,RESP_DATE,CRRALL,GEO_ID,DRRINT&for=place:*&in=state:13"); $content = json_decode($homepage, true); //Table is created on for view purposes. echo "<table border='1'"; $j = 1; $insert_string = ""; foreach ($content as $character) { echo "<TR>"; $fieldcount = count($character); for ($x = 0; $x < $fieldcount; $x++) { //$j>1 - We are excluding first iteration because it contains field names // In this for loop, $insert_string keeps on concatenating all the values in the fields in a string with quotes and comma in between if($j > 1){$insert_string .= "'".$character[$x]."',";} echo "<td>$character[$x]</td>"; } echo "</TR>"; // rtrim removes the last comma and gives us a clean string of values in quotes which we can plug in insert statement. $insert_string = rtrim($insert_string, ","); $j = $j +1; if($insert_string <> ""){ $sql = "INSERT INTO edtables.dbo.Demog_CensusResponse_GACities_2020 (NAME, DRRALL, CRRINT, RESP_DATE, CRRALL, GEO_ID, DRRINT, state, place) VALUES( $insert_string )"; $stmt = sqlsrv_query( $conn, $sql); if( $stmt === false ){ die( print_r( sqlsrv_errors(), true)); } } //Below we are setting the $insert_string back to nothing $insert_string = ""; } echo "</table>"; ?></body></html>




Viewing all 163 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>