Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select integer

Author  Topic 

lwavery769
Starting Member

3 Posts

Posted - 2013-07-11 : 13:21:48
Hi, I'm trying to select a record in Access through PHP.
I've tried:

SELECT * FROM Table1 WHERE 'FullName' = 'ABNER AVERY'
Failed!

SELECT * FROM Table1 WHERE FullName = 'ABNER AVERY'
Success, correct display

SELECT * FROM Table1 WHERE INDI_ID =64 / "SELECT * FROM Table1 WHERE \"INDI_ID\"=64"
No Error, no display

SELECT * FROM Table1 WHERE INDI_ID = 64 / SELECT * FROM Table1 WHERE INDI_ID=64
Error "(Ào" no display

SELECT * FROM Table1 WHERE INDI_ID='64'
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\xampp\htdocs\averykin\testdb.php on line 10
22005

SELECT * FROM Table1 WHERE INDI_ID=\"64\"
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\averykin\testdb.php on line 10
07001
MY code:
$conn=odbc_connect('genealogy','','');//dsn

$sql="SELECT * FROM Table1 WHERE INDI_ID = 108";
//
//FullName ='ABNER AVERY'
//=#27-Sep-50# finds dates equal to 27 September 1950
$result=odbc_exec($conn,$sql);echo odbc_error($conn);
if (odbc_fetch_row($result))
{
$assoc=array();
while($user_detail = odbc_fetch_array($result) ) {
$assoc = array_push_assoc($assoc, 'INDI_ID', $user_detail["INDI_ID"]);
$assoc = array_push_assoc($assoc, 'Given', $user_detail["Given"]);

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-11 : 13:24:15
quote:
Originally posted by lwavery769

Hi, I'm trying to select a record in Access through PHP.
I've tried:

SELECT * FROM Table1 WHERE 'FullName' = 'ABNER AVERY'
Failed!

SELECT * FROM Table1 WHERE FullName = 'ABNER AVERY'
Success, correct display

SELECT * FROM Table1 WHERE INDI_ID =64 / "SELECT * FROM Table1 WHERE \"INDI_ID\"=64"
No Error, no display

SELECT * FROM Table1 WHERE INDI_ID = 64 / SELECT * FROM Table1 WHERE INDI_ID=64
Error "(Ào" no display

SELECT * FROM Table1 WHERE INDI_ID='64'
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\xampp\htdocs\averykin\testdb.php on line 10
22005

SELECT * FROM Table1 WHERE INDI_ID=\"64\"
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\averykin\testdb.php on line 10
07001
MY code:
$conn=odbc_connect('genealogy','','');//dsn

$sql="SELECT * FROM Table1 WHERE INDI_ID = 108";
//
//FullName ='ABNER AVERY'
//=#27-Sep-50# finds dates equal to 27 September 1950
$result=odbc_exec($conn,$sql);echo odbc_error($conn);
if (odbc_fetch_row($result))
{
$assoc=array();
while($user_detail = odbc_fetch_array($result) ) {
$assoc = array_push_assoc($assoc, 'INDI_ID', $user_detail["INDI_ID"]);
$assoc = array_push_assoc($assoc, 'Given', $user_detail["Given"]);

If your second case works correctly and displays the record correctly, what is the issue you are facing? The second query seems sytnactically correct to me as well.
Go to Top of Page

lwavery769
Starting Member

3 Posts

Posted - 2013-07-11 : 13:35:22
I need to select records by the integer in the INDI_ID field.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-11 : 13:55:49
Remove the single quote and it should work.
SELECT * FROM Table1 WHERE INDI_ID=64
But in your case if it is not returning any records, can it be because there are no records in the table that match that filter? You could also try this:
SELECT * FROM Table1 WHERE CStr(INDI_ID)='64'
Go to Top of Page

lwavery769
Starting Member

3 Posts

Posted - 2013-07-11 : 17:37:50
Thanks, but no luck. This works:
SELECT * FROM Table1 WHERE FullName = 'ABNER AVERY' Success, correct display:

(ÀoRows returned: -1
Key = INDI_ID Value = 64
Key = Given Value = ABNER
Key = Surname Value = AVERY
Key = Birth Value = 28 MAY 1712
Key = BirthPlace Value = Groton, New London, Connecticut, USA
Key = Death Value = 13 AUG 1771
Key = DeathPlace Value = Montville, New London, Connecticut, USA
Key = Mother Value = ELIZABETH BILL
Key = Father Value = JONATHAN AVERY
Key = Spouse1 Value = AMY FOX
Key = Marriage1 Value = 22 MAY 1740

but,
SELECT * FROM Table1 WHERE INDI_ID = 64 produces an Error "(Ào" and no display
Go to Top of Page
   

- Advertisement -