Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connecting to access database with php 1

Status
Not open for further replies.

ralphonzo

Programmer
Apr 9, 2003
228
GB
does anyone know how to connect to an access database via php? i'm an asp developer (sorry!) and php leaves me bog-eyed i'm afraid. this is the script that i've ended up with:
Code:
if(is_uploaded_file($_FILES['file']['tmp_name']) && $_SESSION['upload'] == "true")
	{
		move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name'].'.jpg');
		$file = $_FILES['file']['name'];
		$_SESSION['output'] = "Correct!";
		$_SESSION['upload'] = "true";
		
		$db = '..\..\db\isview.mdb';
		$conn = new COM('ADODB.Connection');
		$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
		
		$sql = "INSERT INTO e_cat (cat_code, cat_subcode) VALUES (".$icode.", ".$_FILES['file']['name'].")";
		$conn->Execute($sql);
echo $sql;
		
		$conn->Close();
	}
the image is being uploaded (from earlier in the script) and the echo reports a favourable sql insertion, but the database remains uninserted!! any ideas folks??

ralph
 
the easiest way is to create a system DSN and then use that to create an odbc connection.

if you have called the DSN "MyConnection" you would then connect by
Code:
$con = odbc_connect('MyConnection','','');
$exc = odbc_exec($con,$sql);
 
thanks for the input, but i get the same response - a good looking sql but no action. this is the code i used:
Code:
$con = odbc_connect('..\..\db\isview.mdb','','');
		$sql = "INSERT INTO e_cat (cat_code, cat_subcode) VALUES (".$icode.", '".$_FILES['file']['name']."')";
		$exc = odbc_exec($con,$sql);
is there something fundamentally stupid that i'm doing or not doing? there usually is(n't)!!!
 
nope - that's not a dsn.

go to the control panel, admin tools, odbc data sources and create an odbc system dsn. the argument in the odbc_connect() function is the name of the DSN and not the name of the mdb.
 
my god it worked!!!

you are the original star.

thankyou, and please accept a star for your invaluable help,

regards,

happy ralph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top