SQL + Front Page - Making a Connection

mtairhead

Registered User.
Local time
Today, 16:59
Joined
Oct 17, 2003
Messages
138
I know that I can use SQL Server as a backend in Front Page... Can anyone point me in the right direction (A link or something?) as to how I would go about doing that? I need to create a database connection, and I have no clue. I've done it with Access before (I think) but I know that it's different with SQL, or at least I think it is.

Don't I have to create a ODBC Connection or the like? On what? My SQL server? My individual computer? erp...

</idiot>

Andrew
 
Keith,

I don't want to sound like and idiot, but where do these strings go? ...I'm used to using mySQL and PHP. I'm planning on using MSSQL and PHP now. I've researched and found that they aren't very different, but it would appear that I need to call an ODBC connection in my connection string, rather than mySQL...

So, instead of....
$connect = mysql_connect('host','user','pass');

Do I use...
$connect = odbc_connect('database','user','pass');

If so, what is... [Found on the connectionstrings.com in the ODBC section]?
"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"

Thanks for helping a crazy like me,

Andrew
 
I've seen the light...

I was able to connect with success to the SQL server via an ODBC connection string and a little PHP.

Thanks!
 
...For future readers:

For those attempting to use PHP and SQL in the future...
I set up an ODBC connection on my web server to my SQL database, localed on my SQL server (Start > Control Panel > Administrative Tools > Data Sources). Then, I used PHP to connect to the ODBC connection. I used the following code:

PHP:
$dsn = "Driver={SQL Server};Server=YourSQLServerName;Database=YourSQLDatabaseName;Uid=UserNameForSQLServer;Pwd=UserPassword;";

$conn = odbc_connect ( $dsn, 'SQLServerUserName', 'SQLPassword') or die ('Unable to connect');

For those, like myself, who can use PHP w/mySQL but are lost when using PHP w/ODBC connections, I've ripped the following off of the manual from PHP.net's ODBC_connect article.

PHP:
<?php
//================================================================

  // Configure connection parameters
  $db_host        = "server.mynetwork";
  $db_server_name = "Dev_Server";
  $db_name        = "Dev_Data";
  $db_file        = 'c:\dbstorage\dev.db';
  $db_conn_name  = "php_script";
  $db_user        = "dbuser";
  $db_pass        = "dbpass";

//================================================================
  $connect_string = "Driver={Adaptive Server Anywhere 8.0};".
                   "CommLinks=tcpip(Host=$db_host);".
                   "ServerName=$db_server_name;".
                   "DatabaseName=$db_name;".
                   "DatabaseFile=$db_file;".
                   "ConnectionName=$db_conn_name;".
                   "uid=$db_user;pwd=$db_pass";

  // Connect to DB
  $conn = odbc_connect($connect_string,'','');

  // Query
  $qry = "SELECT * FROM my_table";

  // Get Result
  $result = odbc_exec($conn,$qry);

  // Get Data From Result
  while ($data[] = odbc_fetch_array($result));

  // Free Result
  odbc_free_result($result);

  // Close Connection
  odbc_close($conn);

  // Show data
  print_r($data);

//================================================================
?>

I successfully used the commands to display all records in my database. Anyone with PHP experience can adapt these commands to suit their needs with their own queries, etc.

You'll find that script in the comments section. It's by "aamaral at 0kbps dot net."

Thanks all,

~Andrew
 
Last edited:

Users who are viewing this thread

Back
Top Bottom