php sintax for Access SQL Statements

Hi,
I am a beginner and would appreciate help on this small project where I use php (in fact PHPRunner) with an Access database.

I receive the error "Parse error: syntax error, unexpected 'CustomQuery' (T_STRING)..." with the code below. What would be the correct syntax?

$sql= "INSERT INTO ItensVistorias ( IDVisitoria, Descricao, Ord ) SELECT ApoioAddItensVistorias.ApoioA, ApoioAddItensVistorias.Descricao, ApoioAddItensVistorias.Ord FROM ApoioAddItensVistorias;"  
CustomQuery($sql);

Any indication on where I could find  samples of sql statements for PHP x Access would also be appreciated.

Thanks in advance,
Robert
Robert HesterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris Harte2015 Top Expert (Most Article Points)Commented:
You are missing a semi-colon at the end of the $sql assignment

$sql= "INSERT INTO ItensVistorias ( IDVisitoria, Descricao, Ord ) SELECT ApoioAddItensVistorias.ApoioA, ApoioAddItensVistorias.Descricao, ApoioAddItensVistorias.Ord FROM ApoioAddItensVistorias;" ;  

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PatHartmanCommented:
Copy the SQL string and try to run it as a query in Access.  That will help you identify any syntax error in the string itself.  If the query runs, then you know that there is something wrong with the PHP part of the code.

PS - SQL has some words that are reserved.  I don't know if those words in different languages are also reserved.  For example - Description or Desc.
Robert HesterAuthor Commented:
Does this apply to any string in Access? Can I just copy the string in Access with any of its functions and simply copy and paste them? Even UPDATE strings?

What if I have functions or variables such as below (which also does not work)? Is there a general rule for quotes?


$sql ="Update xxxApoio set ApoioA=".$_SESSION["VistoriaID"];
CustomQuery($sql);
Robert HesterAuthor Commented:
Thank you both,,,Chris was fast and direct.
Pats explanation is of great interest to me. I´ll be back soon for more on this subject.

Robert
PatHartmanCommented:
You have to expand the string to get the values from the PHP functions.  You can only use valid "Access" SQL syntax in an Access query.

If you have the ability to put stops in your code.  Do that.  As soon as $sql has the string that will be sent to Access, print it to your debug window (or whatever PHP uses) and copy it for use in Access.  The biggest problem people have creating SQL is syntax and it is next to impossible to identify syntax errors in code.  Once you see how the string looks after it is built, if you can't immediately see the syntax error, you can copy it into a new querydef and let Access find it for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.