ellandrd
asked on
Execute MS Access Query
is it possible to run MS Access Query and how using PHP?
query name "qry_ListUserEmailAddress"
query name "qry_ListUserEmailAddress"
ASKER
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\P ersonal\in dex.php on line 16
Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P ersonal\in dex.php on line 18
Warning: odbc_result(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P ersonal\in dex.php on line 20
Username is
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\P
Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P
Warning: odbc_result(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P
Username is
ASKER
them links dont tell me how to run query in ms access db!
can you help?
can you help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
?>
<?
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
$rs = $conn->execute($strSQL);
$parameter=$rs->Fields(0);
echo ($parameter->value);
$rs->Close();
$conn->Close();
$rs=null;
$conn=null;
?>
ASKER
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\P ersonal\in dex.php on line 5
Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P ersonal\in dex.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...
Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\admin\P
code:
<?php
$connection = odbc_connect("mssql_mirror
$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...
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