Solved

Quotation marks PHP / interbase query

Posted on 2013-11-06
6
375 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
  • 4
  • 2
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
Thanks, that did the trick.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now