SQL not working in my SQL statement.

Ok I have a statement  that works in my MySQL Work Bench but when I wrap the query for php the Query no longer works:

Original:
select
                   li.leadID AS id,
                   IFNULL(MAX(ls.created), li.dateMade) AS created,
                   li.dateStatus AS updated,
                   li.status,
                   IF(li.status = 'New', 1,
                     IF(li.status = 'First Message', 2,
                     IF(li.status = 'Second Message', 3,
                     IF(li.status = 'Third Message', 4,
                     IF(li.status = 'Boneyard', 5, 0
                   ))))) AS weight,
                   li.app_stage AS stage,
                   li.sex,
                   li.state,
                   li.zip,
                   li.birthdate AS dob
                   FROM
                   leads_leadInfo li
               LEFT JOIN leads_checkout lc ON li.leadId = lc.leadId AND lc.deleted IS NULL AND lc.created <= '2015-06-15 12:12:00'
                               LEFT JOIN leads_sources ls ON ls.leadId = li.leadId
               WHERE
                   li.call_center_id=0
                   AND lc.id IS NULL
                   AND ls.created > '2015-06-10 8:00:00'
                   AND (li.email IS NULL OR li.email NOT LIKE '%@medigap360.com')

                        AND state IN ('AZ')
                               GROUP BY id
               HAVING weight > 0 AND created > '2015-06-10 8:00:00'
               ORDER BY
                   weight ASC, created DESC
               LIMIT 1000

Open in new window


If I wrap this in a php variable and echo it out and try to exact the  statement it fails. can you see what I am missing?

$sql = "select
                   li.leadID AS id,
                   IFNULL(MAX(ls.created), li.dateMade) AS created,
                   li.dateStatus AS updated,
                   li.status,
                   IF(li.status = 'New', 1,
                     IF(li.status = 'First Message', 2,
                     IF(li.status = 'Second Message', 3,
                     IF(li.status = 'Third Message', 4,
                     IF(li.status = 'Boneyard', 5, 0
                   ))))) AS weight,
                   li.app_stage AS stage,
                   li.sex,
                   li.state,
                   li.zip,
                   li.birthdate AS dob
                   FROM
                   leads_leadInfo li
               LEFT JOIN leads_checkout lc ON li.leadId = lc.leadId AND lc.deleted IS NULL AND lc.created <= '2015-06-15 12:12:00'
                               LEFT JOIN leads_sources ls ON ls.leadId = li.leadId
               WHERE
                   li.call_center_id=0
                   AND lc.id IS NULL
                   AND ls.created > '2015-06-10 8:00:00'
                   AND (li.email IS NULL OR li.email NOT LIKE '%@medigap360.com')

                        AND state IN ('AZ')
                               GROUP BY id
               HAVING weight > 0 AND created > '2015-06-10 8:00:00'
               ORDER BY
                   weight ASC, created DESC
               LIMIT 1000";
echo $sql;

Open in new window

austinfxAsked:
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.

Julian HansenCommented:
when I wrap the query for php the Query no longer works:

How does it not work?
Is there an error - if so what
Is it that the returned results are non existent / not expected?
What library are you using to connect to the database?

If you can post some code to give the query context it might shed some light. The queries posted are identical so it is most likely something in your code / connection that
Ray PaseurCommented:
This article shows some ways to use MySQL, including several examples that show how to run queries, visualize errors, and return results sets.  Please read it over and post back if you still have specific questions.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

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
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.