• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Execute MS Access Query

is it possible to run MS Access Query and how using PHP?

query name "qry_ListUserEmailAddress"
0
ellandrd
Asked:
ellandrd
  • 3
  • 2
1 Solution
 
snoyes_jwCommented:
Yes.  You'll need to use ODBC to connect the two.
The PHP manual: http://www.php.net/odbc
A little walkthrough showing how to set up the connection: http://www.phpfreaks.com/tutorials/61/0.php
0
 
ellandrdAuthor Commented:
i have connection set up and its working, just need to run query:

what i have is:

<?php
$connection = odbc_connect("mssql_mirror","","");

if ($connection)
{
   echo "fine";
}
else
{
   echo "failed";
   exit;
}

$query = "qry_ListUserEmailAddress";

$result = odbc_exec($connection, $query);

odbc_fetch_row($result);

$username = odbc_result($result,0);

echo "Username is ". $username;

odbc_close($connection);
?>


error messages i get are:

fine
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'., SQL state 37000 in SQLExecDirect in c:\Inetpub\wwwroot\admin\Personal\index.php on line 16

Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\Personal\index.php on line 18

Warning: odbc_result(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\Personal\index.php on line 20
Username is
0
 
ellandrdAuthor Commented:
them links dont tell me how to run query in ms access db!

can you help?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
snoyes_jwCommented:
try this:
$result = odbc_exec($connection, "{CALL $query}");
0
 
dr_dedoCommented:
another method (windows only)
<?
if (!$conn = new COM("ADODB.Connection"))
        exit("Unable to create an ADODB connection<br>");

$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("test.mdb");
$conn->open($strConn);
$strSQL="SELECT parameters.parameter, Table1.min_a, Table1.max_a, Table1.mean_a, Table1.min_b, Table1.max_b, Table1.mean_b, Table1.sd_b, Table1.t, Table1.p
FROM [parameters] INNER JOIN Table1 ON parameters.parameter_id = Table1.parameter
WHERE (((parameters.parameter_id)=1))";
$rs = $conn->execute($strSQL);
$parameter=$rs->Fields(0);
echo ($parameter->value);
$rs->Close();
$conn->Close();
$rs=null;
$conn=null;
?>
0
 
ellandrdAuthor Commented:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Could not find stored procedure 'qry_getntusername'., SQL state 37000 in SQLExecDirect in c:\Inetpub\wwwroot\admin\Personal\index.php on line 5

Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\Personal\index.php on line 10


code:

<?php
$connection = odbc_connect("mssql_mirror","sa","");

$query = "qry_getntusername";
$result = odbc_exec($connection, "{CALL $query}");

while($row = odbc_fetch_array($result))
{
      echo $row['firstName']."<br>";
}

odbc_close($connection);
?>

remember my query exists in our access database, not our MS SQL server.  the query is a pass through query...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now