[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Quotation marks PHP / interbase query

Posted on 2013-11-06
6
Medium Priority
?
389 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 111

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 111

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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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