Iasonic Posted October 31, 2005 Share Posted October 31, 2005 Hi everybody, i am trying to get a connection with php and acces so far nothing seems to work. The code i have comes from a tutorials on this website, but it doesn't work. The tutorial I mad a connection in the system dns and in the user dns, they both don't work. I am working with an IIS v5 server and PHP v4.3 Some help would be very nice. My erro code Warning: odbc_connect(): SQL error: , SQL state 00000 in SQLConnect in C:\Inetpub\accesdbtest\DataAccess.php on line 28 Error in odbc_connect Warning: odbc_close(): supplied argument is not a valid ODBC-Link resource in C:\Inetpub\accesdbtest\DataAccess.php on line 62 [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php [/span][span style=\"color:#007700\"]function [/span][span style=\"color:#0000BB\"]HTML_Head[/span][span style=\"color:#007700\"]() { echo [/span][span style=\"color:#DD0000\"]\" <HTML><HEAD> <TITLE>Processing Form</TITLE> </HEAD> <BODY BGCOLOR=\\"[/span][span style=\"color:#FF8000\"]#D5D5AB\\">\"; [/span][span style=\"color:#007700\"]} function [/span][span style=\"color:#0000BB\"]HTML_Foot[/span][span style=\"color:#007700\"]() { echo [/span][span style=\"color:#DD0000\"]\"</body></html>\"[/span][span style=\"color:#007700\"]; } function [/span][span style=\"color:#0000BB\"]Database_Entries[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$msg[/span][span style=\"color:#007700\"]) { echo [/span][span style=\"color:#0000BB\"]$msg[/span][span style=\"color:#007700\"]; } function [/span][span style=\"color:#0000BB\"]Output_Entries[/span][span style=\"color:#007700\"]() { [/span][span style=\"color:#FF8000\"]/* Make the connection to the database. The syntax is odbc_connect( \'Agezo\' , \'test\', \'test\' ); $cnx will hold the pconnect is used to establish a persistent database connection to the Database until the procedure is completed. */ [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_connect[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'Agezo\' [/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'test\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'test\' [/span][span style=\"color:#007700\"]); if (![/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]Error_handler[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"Error in odbc_connect\" [/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]); } [/span][span style=\"color:#FF8000\"]// send a simple odbc query . returns an odbc cursor [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_exec[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"select Index,FirstName,LastName,PhoneNumber from People\" [/span][span style=\"color:#007700\"]); if (![/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]Error_handler[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"Error in odbc_exec( no cursor returned ) \" [/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]); } echo [/span][span style=\"color:#DD0000\"]\"<table border=1><tr><th>Index</th><th>First Name</th>\"[/span][span style=\"color:#007700\"]. [/span][span style=\"color:#DD0000\"]\"<th>Last Name</th><th>Phone Number</th></tr>\n\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$nbrow[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]0[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]//Local variable to count number of rows // fetch the succesive result rows [/span][span style=\"color:#007700\"]while( [/span][span style=\"color:#0000BB\"]odbc_fetch_row[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cur [/span][span style=\"color:#007700\"]) ) { [/span][span style=\"color:#0000BB\"]$nbrow[/span][span style=\"color:#007700\"]++; [/span][span style=\"color:#0000BB\"]$Index[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_result[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]1 [/span][span style=\"color:#007700\"]); [/span][span style=\"color:#FF8000\"]// get the field \"Index\" [/span][span style=\"color:#0000BB\"]$FirstName[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_result[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]2 [/span][span style=\"color:#007700\"]); [/span][span style=\"color:#FF8000\"]// get the field \"FirstName\" [/span][span style=\"color:#0000BB\"]$LastName[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_result[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]3 [/span][span style=\"color:#007700\"]); [/span][span style=\"color:#FF8000\"]// get the field \"LastName\" [/span][span style=\"color:#0000BB\"]$PhoneNumber[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_result[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]4 [/span][span style=\"color:#007700\"]); [/span][span style=\"color:#FF8000\"]// get the field \"PhoneNumber\" [/span][span style=\"color:#007700\"]echo [/span][span style=\"color:#DD0000\"]\"<tr><td>$Index</td><td>$FirstName</td>\"[/span][span style=\"color:#007700\"]. [/span][span style=\"color:#DD0000\"]\"<td>$LastName</td><td>$PhoneNumber</td></tr>\n\"[/span][span style=\"color:#007700\"]; } echo [/span][span style=\"color:#DD0000\"]\"<tr><td colspan=2>$nbrow entries </td></tr></table>\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#FF8000\"]// close the connection. important if persistent connection are \"On\" [/span][span style=\"color:#0000BB\"]odbc_close[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"]); } function [/span][span style=\"color:#0000BB\"]Error_Handler[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$msg[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]) { echo [/span][span style=\"color:#DD0000\"]\"$msg \n\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]odbc_close[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"]); exit(); } function [/span][span style=\"color:#0000BB\"]Enter_New_Entry[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$FirstName[/span][span style=\"color:#007700\"],[/span][span style=\"color:#0000BB\"]$LastName[/span][span style=\"color:#007700\"],[/span][span style=\"color:#0000BB\"]$PhoneNumber[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#FF8000\"]/* First, we create a connection to our ODBC source. This is done by creating a connection. Once this is done, we are returned an ODBC connection number. We use this number to use the ODBC functions within PHP. */ [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_connect[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\'Agezo\' [/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'test\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'test\' [/span][span style=\"color:#007700\"]); if (![/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]Error_handler[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"Error in odbc_connect\" [/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]); } [/span][span style=\"color:#0000BB\"]$SQL_Exec_String [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Insert Into People (FirstName, LastName,PhoneNumber) Values (\'$FirstName\', \'$LastName\', \'$PhoneNumber\')\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]odbc_exec[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$SQL_Exec_String [/span][span style=\"color:#007700\"]); if (![/span][span style=\"color:#0000BB\"]$cur[/span][span style=\"color:#007700\"]) { [/span][span style=\"color:#0000BB\"]Error_handler[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#DD0000\"]\"Error in odbc_exec( no cursor returned ) \" [/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$cnx [/span][span style=\"color:#007700\"]); } [/span][span style=\"color:#0000BB\"]odbc_close[/span][span style=\"color:#007700\"]( [/span][span style=\"color:#0000BB\"]$cnx[/span][span style=\"color:#007700\"]); } [/span][span style=\"color:#0000BB\"]$strOldEntries [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Previous Entries in database\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$strNewEntries [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Updated version of databse (after entries)\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]HTML_Head[/span][span style=\"color:#007700\"](); [/span][span style=\"color:#0000BB\"]Database_Entries[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$strOldEntries[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]Output_Entries[/span][span style=\"color:#007700\"](); [/span][span style=\"color:#0000BB\"]Enter_New_Entry[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$FirstName[/span][span style=\"color:#007700\"],[/span][span style=\"color:#0000BB\"]$LastName[/span][span style=\"color:#007700\"],[/span][span style=\"color:#0000BB\"]$PhoneNumber[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]Database_Entries[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$strNewEntries[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]Output_Entries[/span][span style=\"color:#007700\"](); [/span][span style=\"color:#0000BB\"]HTML_Foot[/span][span style=\"color:#007700\"](); [/span][span style=\"color:#0000BB\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment https://forums.phpfreaks.com/topic/2770-access-php-odbc-connection-error/ Share on other sites More sharing options...
Thrakorzog Posted September 13, 2006 Share Posted September 13, 2006 Your code is kinda hard to read, but I have a similar setup, I use the following as an include file: <?php $conn=odbc_connect('databaseName','UN','PW'); if (!$conn) { exit("Connection Failed: " . $conn); } ?> I have had the ODBC setup for a long time using it with ASP, but I am converting my stuff to PHP. Everything else outside of this call, was done in the System DSN to setup the database as an ODBC accessible datasource. Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/2770-access-php-odbc-connection-error/#findComment-91229 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.