Jump to content

Iasonic

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Iasonic's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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--]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.