using the following code i get an error from line 5 my error is

Fatal error: Uncaught PDOException: SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. in C:\xampp\htdocs\dailysales\includes\CPeriodOrdersJson.php:5 Stack trace: #0 C:\xampp\htdocs\dailysales\includes\CPeriodOrdersJson.php(5): ->('sqlsrv:Server=F...', 'LocalAdmin', 'CrispyCrackers') #1 {main} thrown in C:\xampp\htdocs\dailysales\includes\CPeriodOrdersJson.php on line 5

any ideas please it used to work before i moved my database to a new server

<?php

include("sqlcalendar.php");

$db = new PDO("sqlsrv:Server=FFP-X3DB\X3;Database=FFP_WebServices", "LocalAdmin", "CrispyCrackers");

$row=$db->prepare("FFP_WebServices.dbo.WEBSERV_PERIOD_ANNUAL_FIGURES_CUMMULATIVE_SELECT");

$row->execute();//execute the query

//create the array
$json_data['cols'] = array(
  array('label' => 'Mon', 'type' => 'string'),
  array('label' => 'COrdersTP', 'type' => 'number'),
  array('label' => 'COrdersAP', 'type' => 'number')
);

$rows = array();
foreach($row as $rec)//foreach loop
{
  $temp = array();
  $temp[] = array('v' => (string) $rec['Mon']);
  $temp[] = array('v' => (float) $rec['COrdersTP']);
  If ((int)$rec['Per'] < ($CurrentPeriod)) {
    $temp[] = array('v' => (float) $rec['COrdersAP']);}
  Else {}   
  $rows[] = array('c' => $temp);
}
$json_data['rows'] = $rows;

//built in PHP function to encode the data in to JSON format
echo json_encode($json_data, JSON_NUMERIC_CHECK);
?>

Dani AI

Generated

The error shown (SQLSTATE[08001] / Named Pipes Provider … [53]) means the PHP/ODBC client cannot reach the SQL Server instance — it’s a connectivity problem, not an authentication error. Common root causes are: the instance name or DSN was malformed (backslash needs escaping in PHP strings), the server is listening only on TCP while the client tries Named Pipes, the SQL Browser/service for named instances is not available, Windows firewall is blocking the SQL port, or a driver/bitness mismatch exists between PHP/XAMPP and the installed Microsoft ODBC driver.

Useful DSN variants to test (note the double backslash to represent the instance, or force TCP+port):

# escape the instance backslash in PHP
'sqlsrv:Server=FFP-X3DB\\X3;Database=FFP_WebServices'

# force TCP and an explicit port (works if the instance is bound to a known port)
'sqlsrv:Server=tcp:FFP-X3DB,1433;Database=FFP_WebServices'

Typical troubleshooting/checklist (order matters for fast isolation):

  • Verify name resolution from the web host (ping or DNS lookup of FFP-X3DB).
  • From the web host, test TCP reachability to the SQL port (telnet/Test-NetConnection to port 1433 or the assigned instance port).
  • If using a named instance, confirm SQL Server Browser service is running and UDP 1434 is allowed, or assign a static TCP port to the instance and use that port in the DSN.
  • In SQL Server Configuration Manager enable TCP/IP for the instance and restart the service.
  • Add an inbound firewall rule for the SQL Server executable or the assigned TCP port.
  • Confirm the PHP/ODBC driver bitness matches XAMPP (x86 vs x64) and consider upgrading the ODBC driver if the server shows Driver 11 in the error (newer drivers are available).

’s suggestion to test with the lower-level sqlsrv_connect (or a minimal PDO test using an escaped DSN) is a good way to isolate whether the problem is DSN/driver or server-side. Also, public posts containing real credentials should be redacted.

Recommended Answers

All 2 Replies

can you able to access the database without any issue using your php code

Can you try below code for checking connection with Database

$serverName = "";
$userName = "";
$userPassword = "";
$dbName = "";
$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.