Solved

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

Posted on 2009-05-03
19
750 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now