I have an EasyPHP web server, and Im loading some code from my database, here is my code:
**<?php
// Connect to database server
$server = 'MYPC\SQLEXPRESSSERVER';
$connectionInfo = array("UID"=>"UserID", "PWD"=>"Password", "Database"=>"TestDatabase")// Connect to SQLSRV
$link = $server($server, $connectionInfo);
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
// Query to execute
$query = "SELECT [UserID],[Username] FROM [USERTABLE] WHERE [UserName] = 'Hi'";
$stmt = sqlsrv_query( $link, $query);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC))
{
echo "Col1: ".$row[0]. "
";
echo "Col2: ".$row[1]. "
";
}
sqlsrv_free_stmt($stmt);
sqlsrv_close( $link);
?>**
When I upload it to my web server I get an error:
Fatal error: Call to undefined function MYPC\SQLEXPRESSSERVER() in C:\Users\MyCPUName\Desktop\HTML\Data2.php on line 8
Line 8 is used to connect to my database, without it the code wouldn't work. I need help with this code, please.
You have to call sqlsrv_connect()
to connect to your database. Otherwise you have no link to your database.