Jump to content

DB code not working


Recommended Posts

I'm new to PHP and just copied some code from a LAMP box to my Windows server. I ported the mySql database to MS Sql and modified all the PHP code to use MSSQL_* instead of MYSQL_* and made sure that php.ini properly loads c:\php\ext\php_mssql.dll


When the following code runs, it just fails, silently. I only see "Config Start" in the output. Nothing after it.


Any advice?






<p>Config Start</p>


$db = "mydbname";

$link = mssql_connect("localhost","username","userpw") or die("Could not connect: ");


<p>Config End</p>

Link to comment
Share on other sites



I realized after the fact that I hadn't added any MSSQL.* settings to php.ini.  Now that I have, I am getting the "die" code to display, ie; "Could not connect: "


I'm doing my best to RTFM but am only very slowly getting ahead. Any assistance would be greatly appreciated.


This is how I have the PHP code now:



$db = "[dbname]";

$link = mssql_connect("localhost\SQLEXPRESS","[username]","[password]") or die("Could not connect: ");






mssql.allow_persistent = 1

mssql.max_persistent = -1

mssql.max_links = -1

mssql.min_error_severity = 10

mssql.min_message_severity = 10

mssql.compatability_mode = 0

mssql.connect_timeout = 5

mssql.timeout = 60

mssql.textsize = -1

mssql.textlimit = -1

mssql.batchsize  = 0

mssql.datetimeconvert = 1

mssql.secure_connection = 0

mssql.max_procs = -1

mssql.charset = UTF-8


Link to comment
Share on other sites

If you echo mssql_get_last_message you can probably find out why the connection failed. Also, are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to display all the errors it detects. Stop and start your web server to get any change made to php.ini to take effect and confirm that the actual setting was changed using a phpinfo() statement.

Link to comment
Share on other sites

I have now added the code you mention (just found it myself and was going to report update here and saw you thought of the same thing -- cool);


I also added the two lines you suggested to my php.ini file (and restarted the service).  Still getting nothing. And mssql_get_last_message(); is blank.


I guess my connect string is incorrect somehow. DA114 is my machine name.



$db = "[db_name]";

$link = mssql_connect("DA114\SQLEXPRESS","[username]","[password]") ;

echo "<p>yo 1</p>";

echo mssql_get_last_message();

echo "<p>yo 2</p>";



Link to comment
Share on other sites

I'm not getting any errors at all, until I actually run a query.  I have tested the query by copying it into a new query window in SQL Server Manager, and it works. Yet, through the PHP connection I get a fail, and no explanation.


I'm going to have to take a break from this, or I'm going to shoot someone.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.