KB Article 9123

Contact Tech Support

 Email Tech Support
 (250) 655-1766
 [7:30 - 5:00 PST]
Your Meeting ID will be Provided by a Rep.
Tech Support
Tech Support Home
Software Updates
Knowledge Base Search
Recent KB Articles
Product FAQs
Code Samples
Tech Blog
System Requirements
Installation Instructions
Support Testimonials
Contact us to...
Create a Ticket
Request a Free Demo
Suggest a New Feature
Submit Feedback
Upload a Large File
Other Services
Software Training
Professional Services

How to connect to MSSQL using WebSmart PHP templates

Product: WebSmart PHP Type: How to

You can connect to your Microsoftt SQL server (MSSQL) using the WebSmart PHP MySQL Templates. Once the Wizard completes, you just need to change a few lines of connection code and you should be good to go.

This example uses the PHP MySQL Record Listing template. In the WebSmart IDE:

  1. Choose File > New > PHP Templates > MySQL > Idaho > Record Listing.tpl
  2. Enter a Script name, web Title, FTP site etc and hit next. If you don't have a Destination FTP, Database or Web Path defined you will have to Add them using the Add buttons on this screen - see steps 6 and 7 of the WebSmart installation instructions.
  3. Once your FTP and Database are defined, choose them from the appropriate Drop Down list.
  4. Click Next, Fill in your Programmer Name (optional) and click Next Enter the Table and Database name you want to use in your program. If this fails with a table not found message, check the table name or the Database definition created from Step 7 in the WebSmart installation instructions.
  5. Click Next and then Next again, passing the Calculated Fields panel. If you successfully connected to you database in step 5 you will see the fields in your file listed here. Double Click, drag and drop or use the Arrow buttons to select the field columns you want to display in your script.
  6. Click Next and define a filter if you wish or Click Finish. The code that will need to be changed is below
  7. The connection code automatically generated will be near the top of you script and look something like this:
    global $mysqlconn;
    $mysqlconn = xl_mysql_connect();
    // connect failed
      die('Could not connect: ' . mysql_error());  
    // select database
    $db_selected = xl_mysql_select_db($mysqlconn);
    // if no database selected
      die('Could not select database');
    Change it to look like this using your own IP and Database name:
    global $server;
    $server = '';
    // If connecting to a port different from the default use: $server = "";
    $link = mssql_connect($server,'userid', 'password');
    // connect failed
      die('Could not connect: ' . mssql_get_last_message());  
    // select database
    $db_selected = mssql_select_db('harmonics');
    // if no database selected
      die('Could not select database');
  8. Near the bottom of you Display function is the connection close. Change this:
    To this:
  9. Then replace any of the mysql functions with calls to the mssql functions. For example, mysql_query() turns into mssql_query(), mysql_fetch_array() turns into mssql_fetch_array().

That should be it. If you have any questions at all please contact BCD Tech Support at (250)655-1766 (0730-1700 PT) or email excel@excelsystems.com.

Rate This Article

Did this example help you to achieve your goal?
 Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

Email Address:
Please enable JavaScript in order to rate this page.