Solved

how can i put a username and password of ms access dtabase?

Posted on 2009-05-03
19
770 Views
Last Modified: 2012-06-27
i have a php application with ms access database, there is no username and password in that but i want to use a username and password of that. where can i do that?
0
Comment
Question by:designersx
  • 11
  • 6
  • 2
19 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 24293088
To set up users and passwords in your Access database you must use the Access security tools.
However, this is not a trivial step and you need to set aside quite a bit of time to get to grips with it.

Are you wanting to identify each user or are you just looking to provide the same username and password in your connection string for all users?
0
 

Author Comment

by:designersx
ID: 24293127
i am looking for the same username and password in your connection string for all users.

the below works on the localhost but not when i upload it. i have not set up any username and password of mdb database. so why there is a problem coming that way????????

just tell me when i will upload it what i should enter in the first line.
<?php
 $con=odbc_connect('win','','');
 if($con)
	echo "connection is valid";
else
	echo "error in the connection";
exit;
?>

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
ID: 24293174
I can't help with the php code.

If you have not set up any specific security in your Access database then there is not normally a need to supply a username and password.
However, the default user is 'Admin'  with no password, so you could try that, I guess.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:designersx
ID: 24293192
even this error is coming:-

error in the connection

<?php
 $con=odbc_connect('win','admin','');
 if($con)
	echo "connection is valid";
else
	echo "error in the connection";
?>

Open in new window

0
 
LVL 84
ID: 24293685
Is there no other information you can get from the failure? That is, could you not include error code that would perhaps be more specific as to the reason why the connection is failing? Like peter, I'm not familiar with PHP so can't really suggest any code, but I'd be surprised if there were not a more verbose method for this situation which would give you more info ...
0
 

Author Comment

by:designersx
ID: 24293736
actually i am using iis server on which i am uploading the files, and not able to make connection to mdb database with php ?
0
 
LVL 84
ID: 24293814
Right, but does PHP not have any error reporting methods? As I said, I'm not familiar with PHP so can't really tell you, but at this point you're simply guessing as to exactly what the problem might be ... if you can use the error reporting methods of PHP you might be able ferret out the acutal cause of this problem, instead of trying to guess what it may be.

Also, have you added an ODBC connection to the webserver? You might prefer to use a DSN-less connection. This site has a code sample showing how to do that:

http://www.webcheatsheet.com/php/odbc_connection.php
0
 

Author Comment

by:designersx
ID: 24293836
sir this is whati don't know how to add an odbc connection to the webserver.
0
 
LVL 84
ID: 24293841
You can use code to add an ODBC connection to the server, but you'd be better off using the DSN-less methods discussed at the link I provided above.
0
 

Author Comment

by:designersx
ID: 24294084
i am uploading my files on ftp.designers-x.com/projects/php_with_mdb/mydb.mdb 

can u tell me what can be the correct path . please check line 3


Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x6a5c Thread 0x6978 DBC 0x70e2c9c Jet'.' in D:\stuff\root\designers-x.com\wwwroot\projects\php_with_mdb\1.php:3 Stack trace: #0 D:\stuff\root\designers-x.com\wwwroot\projects\php_with_mdb\1.php(3): com->Open('DRIVER={Microso...') #1 {main} thrown in D:\stuff\root\designers-x.com\wwwroot\projects\php_with_mdb\1.php on line 3
 <?php
    $conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=ftp://designers-x.com//projects//php_with_mdb//mydb.mdb");
	
	$rs = $conn->Execute("SELECT myfield FROM mytable");
    while (!$rs->EOF) {
    $fv = $rs->Fields("myfield");
    echo "Value: ".$fv->value."<br>\n";
    $rs->MoveNext();
    } 
    $rs->Close(); 
 ?>

Open in new window

0
 
LVL 84
ID: 24294316
A quick search on your error returned this:

http://support.microsoft.com/kb/295297

i.e a Permissions error ... IOW, contact your ISP and ask them how, exactly, they recommend you connect to your database. Most ISPs have knowledgebases or user forums that can be much more specific than we can.
0
 

Author Comment

by:designersx
ID: 24294459
i have got the path and now able to run on the server.

my code below works fine. since this is dsn-less connection.

please just tell me how i can count the total no. of rows in the table below, just tell me that.
<?php
 
    $conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    
	$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\fantaay\\php_with_mdb\\2\\mydb.mdb");
    
	$q="SELECT myfield FROM mytable";
	
	$rs = $conn->Execute($q);
   
    while (!$rs->EOF) {
   
    $fv = $rs->Fields("myfield");
    
	echo "Value: ".$fv->value."<br>\n";
   
    $rs->MoveNext();
    
	} 
   
    $rs->Close(); 
 ?>	

Open in new window

0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 50 total points
ID: 24294818
$rs="SELECT Count(*) As RecCount FROM MyTable"

<other code here>
$fv = $rs->Fields("RecCount");

your $fv variable should contain the Recordcount ...
0
 

Author Comment

by:designersx
ID: 24295704
very much thanks for the last code, can please tell me in the above code, if i want to do find the maximum id or record in the database, then what should i do?
0
 

Author Comment

by:designersx
ID: 24295710
i mean to say last, max record in the table
0
 

Author Comment

by:designersx
ID: 24295800
error in line 9 is coming when i do like this.

Catchable fatal error: Object of class variant could not be converted to string.


this was the code i used when i was doing DSN connetions.now i am doing dsn-less connections.
$sql1="select max(tbldistributor.id) as id from tbldistributor";
$rs1 = $conn1->Execute($sql1);
while (!$rs1->EOF) {
		$fv = $rs1->Fields("id");
		$rs1->MoveNext();
	}
 
$count=$fv;
echo $count;

Open in new window

0
 

Author Comment

by:designersx
ID: 24295806
the above code works fine in dsn connections.
0
 
LVL 84
ID: 24295944
Your error would seem to point you in the right direction. Have you searched for info on that error, and tried some of the fixes suggested? We'd be happy to assist, but EE is really geared as more of a learning experiencing than a "here's my code, fix it for me" sort of place.

Here's some info on PHP strings that may help:

http://us.php.net/language.types.string
0
 

Author Comment

by:designersx
ID: 24301554
I was in fact trying to read a null value as my code was pointing at the wrong database. Therefore the null variable was being returned as a variaint.

this was the problem, after searching, i get to know


thanksk for ur great help respected sir.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
000webhost.com default error log 1 28
DSN-LESS connection to MS Access database 6 31
backup programme - VBA 3 24
Decrypt string by php 7 32
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The viewer will learn how to dynamically set the form action using jQuery.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question