Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > PHP Data Access


Reply
 
Thread Tools Display Modes
  #1  
Old 07-06-2004, 10:30 PM
LittleProgammer LittleProgammer is offline
Newcomer
 
Join Date: May 2004
Location: Texas
Posts: 20
Question PHP Data Access


I am trying to use ODBC to access a MS Access Database and keep getting this error when I try to run it, I am also running Apache and trying to use php code.

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\Program Files\Apache Group\Apache2\htdocs\Access\source\odbc.php on line 3


odbc.php file
PHP Code:
<?

$odbc 
odbc_connect ('Test''root''') or die( "Could Not Connect to ODBC Database!");

if (
function_exists(odbc_fetch_array))
return;

function 
odbc_fetch_array($result$rownumber=-1) {
    if (
PHP_VERSION "4.1") {
        if (
$rownumber 0) {
            
odbc_fetch_into($result$rs);
        } else {
            
odbc_fetch_into($result$rs$rownumber);
        }
    } else {
        
odbc_fetch_into($result$rownumber$rs);
    }
    
    
$rs_assoc = Array();

    foreach (
$rs as $key => $value) {
        
$rs_assoc[odbc_field_name($result$key+1)] = $value;
    }
     return 
$rs_assoc;
}
?>
query.php file
PHP Code:
<?
include 'odbc.php';

$query odbc_exec($odbc"SELECT * FROM Customers") or die (odbc_errormsg());
while(
$row odbc_fetch_array($query)){
    echo 
"Customer First Name: ".$row['customer_first_name']."<br />";
    echo 
"Customer Last Name: ".$row['customer_last_name']."<br />";
    echo 
"Customer Email: ".$row['email_address']."<br />";
    echo 
"<hr />";
}
odbc_close($odbc);
?>
if anyone could help I would appreciate it thanks
__________________
"People that don't make mistakes are people the don't do anything." Author Unkown
Reply With Quote
  #2  
Old 07-12-2004, 11:33 AM
dshap dshap is offline
Newcomer
 
Join Date: Mar 2004
Posts: 7
Default

I'm more familiar with using php with mySQL databases, but from what it seems you are not connecting to the database. Are you using phpdev? (just wondering because you have "root" "" as your user/pass)...In connecting to a mySQL database with mysql_connect(), that first param is the server where the database is located. You have it as "Test". I may be wrong, but try changing it to "localhost" to let it know that the database is running on the same server as the script. Just a thought, I'm new at this

- Dan
Reply With Quote
  #3  
Old 07-12-2004, 06:19 PM
Random Random is offline
Contributor
 
Join Date: Oct 2003
Posts: 747
Default

Well, if what I am reading is the same as what I am thinking, the problem is clear.

You are trying to use the username 'root', and a blank password, which is fine. The problem is that your script is trying to connect to a machine named 'Test', and because it can't find 'Test', it can't connect. Try changing it to localhost, or the address of wherever your DB server is.
Reply With Quote
  #4  
Old 07-13-2004, 08:19 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Do you have a System (or Machine) DSN created that has a name of 'Test', that points to your database? And are you sure the user name is 'root' with a blank password.

In general, if you open an Access Database with out a user name or password, you are connected as 'Admin' with a blank password.

Just a few things to look at.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->