PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 3rd, 2004, 03:39 AM
erwindc erwindc is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 erwindc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face PHP - MS SQL connection

Hello,
is there someone who can help me?
I started with mysql - php connection (no problemo)

but now i would like to connect to a ms sql database instead. Is there someone who can help me with this?

<?php # Script 12.4 - mysql_connect.php
// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.
// Set the database access information as constants.
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PASSWORD', '');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'tz_base');
if ($dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) { // Make the connnection.
if (!mysql_select_db (DB_NAME)) { // If it can't select the database.

// Handle the error.
my_error_handler (mysql_errno(), 'Could not select the database: ' . mysql_error());

// Print a message to the user, include the footer, and kill the script.
echo '<p><font color="red">The site is currently experiencing technical difficulties. We apologize for any inconvenience.</font></p>';
include_once ('includes/footer.html');
exit();

} // End of mysql_select_db IF.

} else { // If it couldn't connect to MySQL.
// Print a message to the user, include the footer, and kill the script.
my_error_handler (mysql_errno(), 'Could not connect to the database: ' . mysql_error());
echo '<p><font color="red">The site is currently experiencing technical difficulties. We apologize for any inconvenience.</font></p>';
include_once ('includes/footer.html');
exit();

} // End of $dbc IF.
// Function for escaping and trimming form data.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.
?>

But now: how to adapt to an ms sql database???
pleasssssse someone can help ???

Reply With Quote
  #2  
Old April 4th, 2004, 01:37 PM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Okay, I tried this for a schoolproject and believe me... IT'S HARD!!!!

First of all, do you use Linux or Windows? When you use Windows, I don't have a clue, if you don't have your own server (on Linux) I don't know either...
I manage to do this on a Debian Linux machine after installing A LOT of extra packages. If you can do the same with a MySQL-database, I suggest to use it. Even creating a very big database is less work than connecting Linux with Microsoft...

Let me know!
Cheers,
__________________
Work to live, don't live to work

Reply With Quote
  #3  
Old April 5th, 2004, 01:23 AM
erwindc erwindc is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 erwindc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well,

I have my own server, but that is windows 2000.

nice belgium site btw
greets

Reply With Quote
  #4  
Old April 7th, 2004, 09:18 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Thx, but it's not belgian... It's dutch. But thx anyway, I think you just recognized some words or something.

Ontopic:
With Win2k it must be less difficult than with Linux. Still, I think it's very hard. I've used FreeTDS, but I don't know if it can be used on Windows too. Take a search for it, there's lots of info when you search for FreeTDS. I stand with my earlier post, when you can do it with mySQL, use MySQL.

Reply With Quote
  #5  
Old May 6th, 2004, 01:29 PM
gloworm-in-nj gloworm-in-nj is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: NJ - USA
Posts: 1 gloworm-in-nj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
if your just looking for code to connect PHP to sql server...

$server = "ipaddressortnumber"; //this is ipaddress-colon-portnumber (i don't know where the picture is coming from)

$user = "username”;

$passwd = “password”;

$db_name = "dbanme”;

$table_name = "tablename”;

$conn = mssql_connect($server, $user, $passwd) or die("Couldn't connect to SQL Server on $server");

mssql_select_db($db_name, $conn);

$query = "SELECT * FROM $table_name ";

$result = mssql_query( $query );

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP - MS SQL connection


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway