sasha_mos Posted January 9, 2011 Share Posted January 9, 2011 Hi, I am having enormous trouble connecting an existing (not programmed by myself) PHP interface to an existing MS SQL DB. I have been accessing a copy of this SQL DB for testing purposes on my local machine from my own self-programmed PHP interface using odbc "system DSN" interfaces. But probably, the odbc interface on my local testing environment will be looking different than on the real server, I guess. I am establishing the odbc connection using code that looks like this: $db_server ="localhost"; $db_name ="testdb"; // $db_user ="testuser"; $db_pass ="test"; $conn = odbc_connect($db_name, $db_user, $db_pass) or die ('Can not connect '. $db_name); This works fine - I can access the db and everything works as it should. The PHP interface that I am trying to integrate in my testing environment does the connection this way: $db_server = "localhost"; # I changed that one from the original server name $db_user = "testuser"; $db_pass = "test"; $db_name = "testdb"; $connection_id = odbc_connect($dbserver, $dbuser, $dbpass); So it seems the connection on the server is done without mentioning the $db_name field. Sounds strange to me, but I am only a novice concerning SQL via odbc - normally I only use MySQL. So when the PHP code tries accessing the db, the following error occurs: Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in D:\xampp\xampp\htdocs\testdb\global.include on line xxx xxx is the line containing "$connection_id = odbc_connect($dbserver, $dbuser, $dbpass); " Any ideas how to get that thing working? I am nearly absolutely sure it's got something to do with the odbc datainterfaces defined on my machine, but I have no idea right now. Any kind of help is highly appreciated! Thanks, Sasha Quote Link to comment https://forums.phpfreaks.com/topic/223891-problems-connecting-a-php-interface-to-an-existing-ms-sql-db-odbc-error/ Share on other sites More sharing options...
Brian Swan Posted January 10, 2011 Share Posted January 10, 2011 This may not be the problem (maybe just typos in the forum post?), but it's worth checking... In your second code example, the parameters that are passed to odbc_connect do not match the names used to define them (they are all missing the underscore in their names). Does this work? $connection_id = odbc_connect($db_server, $db_user, $db_pass); -Brian Quote Link to comment https://forums.phpfreaks.com/topic/223891-problems-connecting-a-php-interface-to-an-existing-ms-sql-db-odbc-error/#findComment-1157462 Share on other sites More sharing options...
sasha_mos Posted January 10, 2011 Author Share Posted January 10, 2011 Hi, thanks for the reply. Sorry that I didnt mention it, the 2nd notation was taken from inside a function, so it actually gets the arguments handed over to it, this works. But the error was much easier: the guy who programmed that webinterface called the variable "$dbserver", but what you actually have to enter there is the ODBC DSN - so just a confusing name... Sorry and thanks! Quote Link to comment https://forums.phpfreaks.com/topic/223891-problems-connecting-a-php-interface-to-an-existing-ms-sql-db-odbc-error/#findComment-1157487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.