Hi,

I'm trying to connect to a MS Access database on a server in PHP without having to use ODBC does anyone have any idea or know how. Please help? Thank you.

Member Avatar for iamthwee

Using ODBC is by far the easiest way to do this, since you can connect to any database, on any computer on your network. It happens to be really simple to configure in Administrative Tools as well.

Is there any reason why you can't or don't want to use ODBC?

Hi,
Thank you for your reply its not that I dont't want o use it, but I'm trying to create an MS Access database and a web page that gets all its information loaded from the MS Access database using PHP code and upload it onto a server. I' ve been able to do from a MySQL database but this other server only has an MS Access. When I research it says to use an ODBC so I'm lost. Do you have any clue on what I should do.

Thank you

hey yo I am sorry but that is very dumb..Why use PHP + MS Access that is a sucky combination. You see php is much much better with MySql. If you really need to use MS Access then I recomend you start getting into Asp.Net which just happens to be a little better with both MySql and Ms Access it really does not matter..You know what here is the code if you listen to me.

First things first. Make sure you have referenced System.Data and System.Data.OleDb like this

<%@ Page Language="C#/VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

Then lets say you have a button and a textbox and the button is suppossed to execute a query from an Ms Access database. Lets also say this is the code for the button and textbox within the aspx page.

<asp:TextBox id="TextBox1" runat="server">
<asp:Button id="Button1" runat="server" text="Execute Query" onclick="Do_Query"></asp:Button>

Then you would have to add this between your <script> tags

void Do_Query(object sender, EventArgs e)
{
            string strQuery = TextBox1.Text;
            OleDbConnection Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourDatabase.mdb");
        	OleDbCommand Com = new OleDbCommand(strQuery, Con);
        	try
        	{
           		 Con.Open();
            		 OleDbDataReader dReader = Com.ExecuteReader();

            		while (dReader.Read())
            		{
                                                //Process Data Here
                                                //For example retrieve values
                                }
                                Con.Close();
                 }         
                 catch (OleDbException ex)
                 {
                                Response.Write(ex.ToString());
                 }
}

And yeah dud that is pretty much it..Trust me it is easier than PHP but anyways w/e..I like PHP too but I only use it with MySql..You can also do what the ppls above me suggested but then there is the issue of accessing remote databases..Lets just say that the database is not in your system how in the hell will you configure the connection..There is no way unless the server does it for you automatically..You dont have that problem with ASP.Net since all you need is the latest version of MDAC wich can be quickly downloaded from Microsoft..Well yeah hopefully this works for ya bud..Peace..

And just to clarify the issue I'm not an egg hater.!;)

hey yo I am sorry but that is very dumb..Why use PHP + MS Access that is a sucky combination. You see php is much much better with MySql. If you really need to use MS Access then I recomend you start getting into Asp.Net which just happens to be a little better with both MySql and Ms Access it really does not matter..You know what here is the code if you listen to me.

First things first. Make sure you have referenced System.Data and System.Data.OleDb like this

<%@ Page Language="C#/VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

Then lets say you have a button and a textbox and the button is suppossed to execute a query from an Ms Access database. Lets also say this is the code for the button and textbox within the aspx page.

<asp:TextBox id="TextBox1" runat="server">
<asp:Button id="Button1" runat="server" text="Execute Query" onclick="Do_Query"></asp:Button>

Then you would have to add this between your <script> tags

void Do_Query(object sender, EventArgs e)
{
            string strQuery = TextBox1.Text;
            OleDbConnection Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourDatabase.mdb");
        	OleDbCommand Com = new OleDbCommand(strQuery, Con);
        	try
        	{
           		 Con.Open();
            		 OleDbDataReader dReader = Com.ExecuteReader();

            		while (dReader.Read())
            		{
                                                //Process Data Here
                                                //For example retrieve values
                                }
                                Con.Close();
                 }         
                 catch (OleDbException ex)
                 {
                                Response.Write(ex.ToString());
                 }
}

And yeah dud that is pretty much it..Trust me it is easier than PHP but anyways w/e..I like PHP too but I only use it with MySql..You can also do what the ppls above me suggested but then there is the issue of accessing remote databases..Lets just say that the database is not in your system how in the hell will you configure the connection..There is no way unless the server does it for you automatically..You dont have that problem with ASP.Net since all you need is the latest version of MDAC wich can be quickly downloaded from Microsoft..Well yeah hopefully this works for ya bud..Peace..

And just to clarify the issue I'm not an egg hater.!;)

1. Stop bumping old threads
2. Even if you bump an old thread, answer to the point. The OP asked for connecting to ms-access using "PHP" and not .net.

Hi, I know the idea is dumb and I think it would be better to do it with asp.net like you said but I am not that familiar with asp.net I have tried a couple of times but can't get it to work with asp.net. It's because I don't know it well enough. If you are willing to help me I am willing to try. I have found a DSN-Less connection code in ASP.Net 2.0 that will display the information from the database, but then I don't know and can't figure out code to display the info the way I want it and the pictures. Thanks for your replies.

hey yo I am sorry but that is very dumb..Why use PHP + MS Access that is a sucky combination. You see php is much much better with MySql. If you really need to use MS Access then I recomend you start getting into Asp.Net which just happens to be a little better with both MySql and Ms Access it really does not matter..You know what here is the code if you listen to me.

First things first. Make sure you have referenced System.Data and System.Data.OleDb like this

<%@ Page Language="C#/VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

Then lets say you have a button and a textbox and the button is suppossed to execute a query from an Ms Access database. Lets also say this is the code for the button and textbox within the aspx page.

<asp:TextBox id="TextBox1" runat="server">
<asp:Button id="Button1" runat="server" text="Execute Query" onclick="Do_Query"></asp:Button>

Then you would have to add this between your <script> tags

void Do_Query(object sender, EventArgs e)
{
            string strQuery = TextBox1.Text;
            OleDbConnection Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourDatabase.mdb");
        	OleDbCommand Com = new OleDbCommand(strQuery, Con);
        	try
        	{
           		 Con.Open();
            		 OleDbDataReader dReader = Com.ExecuteReader();

            		while (dReader.Read())
            		{
                                                //Process Data Here
                                                //For example retrieve values
                                }
                                Con.Close();
                 }         
                 catch (OleDbException ex)
                 {
                                Response.Write(ex.ToString());
                 }
}

And yeah dud that is pretty much it..Trust me it is easier than PHP but anyways w/e..I like PHP too but I only use it with MySql..You can also do what the ppls above me suggested but then there is the issue of accessing remote databases..Lets just say that the database is not in your system how in the hell will you configure the connection..There is no way unless the server does it for you automatically..You dont have that problem with ASP.Net since all you need is the latest version of MDAC wich can be quickly downloaded from Microsoft..Well yeah hopefully this works for ya bud..Peace..

And just to clarify the issue I'm not an egg hater.!;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.