# php and SQL server

**URL:** https://boards.straightdope.com/t/php-and-sql-server/526162
**Category:** Factual Questions
**Created:** [January 23, 2010, 9:31pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162 "2010-01-23T21:31:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![batsto](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@batsto](https://boards.straightdope.com/u/batsto)
#### Post date: [January 23, 2010, 9:31pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/1 "2010-01-23T21:31:57Z")

</div>

I’ve got a php file that works just fine on the MySql server database. I also have a SQL server express database, and tried the same script out on that database…I seem to be able to make the connection to the database, and I changed the references to MYSQL\_query() to mssql\_query(). The script keeps returning the error  
mssql\_query(): supplied argument is not a valid MS SQL-Link resource  
is there anything else I need to know to get this to work on the SQL Server Express? Does MSSQL\_Query take different arguments, or do they have to be in a different format or what?

---

<div class="post-metadata">

### Author: ![Dervorin](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dervorin](https://boards.straightdope.com/u/Dervorin)
#### Post date: [January 23, 2010, 10:04pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/2 "2010-01-23T22:04:31Z")

</div>

I don’t have much experience with PHP and SQL Server, but this might help: [php & MS SQL Server Express?](http://forums.databasejournal.com/showthread.php?t=41085).

One thing to remember is that SQL Server Express is a named instance of SQL Server, not the default instance. What this means is that the server name parameter needs to be servername\SQLEXPRESS, not just servername.

---

<div class="post-metadata">

### Author: ![batsto](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@batsto](https://boards.straightdope.com/u/batsto)
#### Post date: [January 23, 2010, 10:13pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/3 "2010-01-23T22:13:52Z")

</div>

thanks…although it doesn’t seem to be a problem connecting to the database; I had that problem initially and fixed it so it stops giving the ‘unable to connect’ error.  
And I’ve gotten other php scripts to run on this server as a test, simple “Hello World” type stuff. But doing anything to this SQl database is proving difficult.

---

<div class="post-metadata">

### Author: ![Dervorin](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dervorin](https://boards.straightdope.com/u/Dervorin)
#### Post date: [January 23, 2010, 10:25pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/4 "2010-01-23T22:25:25Z")

</div>

It’s possible that the SQL query you’re passing isn’t supported by SQL Server Express - have you tried running the query directly against the database, using Management Studio? Then you’ll at least know that the query is valid.

---

<div class="post-metadata">

### Author: ![batsto](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@batsto](https://boards.straightdope.com/u/batsto)
#### Post date: [January 23, 2010, 10:32pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/5 "2010-01-23T22:32:40Z")

</div>

the query works in management studio–it’s just a simple select \* from table

---

<div class="post-metadata">

### Author: ![batsto](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@batsto](https://boards.straightdope.com/u/batsto)
#### Post date: [January 23, 2010, 10:39pm UTC](https://boards.straightdope.com/t/php-and-sql-server/526162/6 "2010-01-23T22:39:59Z")

</div>

the code that’s giving me trouble is this:

\<html\>  
\<head\>  
\<title\>test\</title\>  
\</head\>  
\<body bgcolor=“black” text=“white”\>  
\<?  
$con = mssql\_connect(’./SQLEXPRESS’,‘username’,‘pasword’);  
mssql\_select\_db(‘myDatabase’, $con)

$sql=“SELECT \* FROM t\_table”;  
$result=mssql\_query($sql,$con);

?\>  
\</body\>  
\</html\>

I changed the username and password to post here, and there is more to the code, but that select statement is on the line that is now returning the error ‘unexpected t\_variable’, which is different than what I got before.
