boubaboubaa Posted March 12, 2008 Share Posted March 12, 2008 I'm new to MSSQL and SQLEXPRESS, had hoped it would work as easily as MYSQL. Having problems with mssql_query. The following test script connects and opens database, but will not create a table. Is it possible that the connection is broken for some reason? <?php $myServer = "AESERVICES\SQLEXPRESS,1033"; $myUser = "user"; $myPass = "password"; $myDB = "dbName"; //connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); if ($selected == true){ echo "database open"; } $tablecreate = "CREATE TABLE members ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(10) NOT NULL DEFAULT '', year VARCHAR(4) NOT NULL DEFAULT '' )"; echo $tablecreate; $result = mssql_query($tablecreate) or die ("Error in query"); ... ?> Any one have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/95883-db-connection-ok-but-not-mssql_query/ Share on other sites More sharing options...
sqlnoob Posted March 21, 2008 Share Posted March 21, 2008 why are you using the connector with variables? Can't you do it without it that way? I mean just place the name, just place your account and just place your password in the connector, instead of defening it, the way you are doing now. I mean it's php, not javascript, so you don't have to define the variables. Quote Link to comment https://forums.phpfreaks.com/topic/95883-db-connection-ok-but-not-mssql_query/#findComment-497576 Share on other sites More sharing options...
sqlnoob Posted March 21, 2008 Share Posted March 21, 2008 I mean this bit! Why is that necessary? -> $myServer = "AESERVICES\SQLEXPRESS,1033"; $myUser = "user"; $myPass = "password"; I'm a noob myself, so don't go after my advise, if you really depend on it. Quote Link to comment https://forums.phpfreaks.com/topic/95883-db-connection-ok-but-not-mssql_query/#findComment-497577 Share on other sites More sharing options...
rhodesa Posted March 21, 2008 Share Posted March 21, 2008 If he wants to store his server info in variables first, that is fine, and it has nothing to do with his problem. In my experience with connecting to MSSQL I had to use the actual hostname or IP of the server for $myServer Quote Link to comment https://forums.phpfreaks.com/topic/95883-db-connection-ok-but-not-mssql_query/#findComment-497579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.