Solved

Quotation marks PHP / interbase query

Posted on 2013-11-06
6
386 Views
Last Modified: 2013-11-06
Hi,

I have a script that selects data from an interbase database using PHP, I am getting an error message when using quotation marks in my query,

I can query the database directly ok.

 Parse error: syntax error, unexpected 'abcde' (T_STRING) in C:\xampp\htdocs\precious\customer.php on line 9

SELECT FIRST 10 CLCTABRE ,CLCTGROUPE ,CLCTVILLIV, CLCTABRE
,case substring(CLCTABRE from 1 for 5)
         when 'abcde' then 'company 1'
         when 'adcdf' then 'company 2'
         else 'Unknown'
       end FROM CLIENT WHERE CLKTSOC = 100

Open in new window

0
Comment
Question by:dan_stan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39627081
Try using backticks (lower case under the tilde, to the left of the number one on the top row of the keyboard).

Or post the entire PHP statement that is used with that query string, thanks.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39627083
Actually, it looks like it's a PHP quotes-related issue.  See if this article helps your understanding of the way PHP uses quotes and apostrophes...
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html
0
 

Author Comment

by:dan_stan
ID: 39627091
Here's the whole code. I'll check the article too.

<?php 
error_reporting(E_ALL);
include_once 'database_connect.php';

// COLLECT SOME DATA FROM IBASE
$dbh  = ibase_connect($host, $username, $password);
$stmt = 'SELECT FIRST 10 CLCTABRE ,CLCTGROUPE ,CLCTVILLIV, CLCTABRE
,case substring(CLCTABRE from 1 for 5)
         when 'abcde' then 'company 1'
         when 'adcdf' then 'company 2'
         else 'Unknown'
       end FROM CLIENT WHERE CLKTSOC = 100';
$sth  = ibase_query($dbh, $stmt);
// CREATE AN ARRAY OF OBJECTS
while ($row = ibase_fetch_object($sth))
{
    $newvalues[] = $row;
}

// THIS MAY NOT BE NEEDED - PHP GARBAGE COLLECTOR WILL HANDLE IT
ibase_free_result($sth);
ibase_close($dbh);

// START MYSQL
$dbh = new PDO('mysql:host=localhost;dbname=swdata', 'root', 'root');

// PREPARE A QUERY
$qry = "INSERT INTO USERDB (keysearch ,firstname,surname,fk_company_id) VALUES (:CLCTABRE, :CLCTGROUPE, :CLCTVILLIV, :COMPANY)";
$stmt = $dbh->prepare($qry);


// USE THE ARRAY OF OBJECTS
foreach ($newvalues as $obj)
{
    // BIND THE OBJECT PROPERTIES INTO THE QUERY
    $stmt->bindParam('CLCTABRE',   $obj->CLCTABRE);
    $stmt->bindParam('CLCTGROUPE', $obj->CLCTGROUPE);
    $stmt->bindParam('CLCTVILLIV', $obj->CLCTVILLIV);
	$stmt->bindParam('COMPANY',    $obj->COMPANY);

    // TRY THE QUERY
    try
    {
        $stmt->execute();
    }

    // IF THERE IS AN EXCEPTION THROWN BY PDO
    catch (PDOException $exc)
    {
        // IF THE EXCEPTION NUMBER IS NOT "DUPLICATE UNIQUE"
        if ($exc->errorInfo[1] != 1062)
        {
            $msg = "FAIL: $qry " . PHP_EOL . $exc->getmessage();
            trigger_error($msg, E_USER_ERROR);
        }
    }
}
                                            
?>

Open in new window

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39627099
Lines 7-12.  Try with double quotes, like this:
$stmt = "SELECT FIRST 10 CLCTABRE ,CLCTGROUPE ,CLCTVILLIV, CLCTABRE
,case substring(CLCTABRE from 1 for 5)
         when 'abcde' then 'company 1'
         when 'adcdf' then 'company 2'
         else 'Unknown'
       end FROM CLIENT WHERE CLKTSOC = 100";

Open in new window

0
 

Author Comment

by:dan_stan
ID: 39627156
Thanks, that did the trick.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39627169
Thanks for the points -- it's a great question.  I'm going to update the article to show how the quotes here caused the parse error.  Best regards, ~Ray
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question