Jump to content

DB Connection OK but not mssql_query


boubaboubaa

Recommended Posts

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?

 

 

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.