Jump to content

PHP MSSQL Help!


zduchene

Recommended Posts

I need the help of the form.  I am using PHP and connecting to MSSQL database :(.

 

I wrote a MSSQL query and tested it on the MSSQL Query Analyzer program where it worked great, did exactly what I wanted it to.  I integrated the query into a php script and I am getting:

 

PHP Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '.'. (severity 15) in C:\webapps\htdocs\ji\ji2.php on line 7 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\webapps\htdocs\ji\ji2.php on line 7

 

Here is the php script along with the query:

 

$q = 'SELECT "estimate"."job number", "DEBTOR"."NAMES", "ESTIMATE"."details1", "debtor"."salesrep", "salesrep"."name" AS "csr", "estimate"."due date", "estimate"."order no", "estimate"."qty1", "estimate"."qty2", "estimate"."qty3", "estimate"."qty4" 
FROM "LIVEDATA_Dosrun"."dbo"."ESTIMATE", "LIVEDATA_Dosrun"."dbo"."DEBTOR", "LIVEDATA_Dosrun"."dbo"."SALESREP", "LIVEDATA_Dosrun"."dbo"."INVOICE" 
WHERE "ESTIMATE"."JOB NUMBER" = 53373 AND "INVOICE"."JOB NO" = "ESTIMATE"."JOB NUMBER" AND "INVOICE"."CSR RECNUM" = "SALESREP"."DATAFLEX RECNUM ONE" AND "DEBTOR"."AC NO" = "ESTIMATE"."DEBTOR"';
$result = mssql_query($q);

 

Any help is appreciated!

Link to comment
Share on other sites

new error:

 

PHP Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '`'. (severity 15) in C:\webapps\htdocs\ji\ji2.php on line 7 PHP Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark before the character string ''. (severity 15) in C:\webapps\htdocs\ji\ji2.php on line 7 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\webapps\htdocs\ji\ji2.php on line 7

Link to comment
Share on other sites

It will be read better if you write it like this:

SELECT

"estimate"."job number",

"DEBTOR"."NAMES",

"ESTIMATE"."details1",

"debtor"."salesrep",

"salesrep"."name" AS "csr",

"estimate"."due date",

"estimate"."order no",

"estimate"."qty1",

"estimate"."qty2",

"estimate"."qty3",

"estimate"."qty4"

FROM

"LIVEDATA_Dosrun"."dbo"."ESTIMATE",

"LIVEDATA_Dosrun"."dbo"."DEBTOR",

"LIVEDATA_Dosrun"."dbo"."SALESREP",

"LIVEDATA_Dosrun"."dbo"."INVOICE"

WHERE

"ESTIMATE"."JOB NUMBER" = 53373 AND

"INVOICE"."JOB NO" = "ESTIMATE"."JOB NUMBER" AND

"INVOICE"."CSR RECNUM" = "SALESREP"."DATAFLEX RECNUM ONE" AND

"DEBTOR"."AC NO" = "ESTIMATE"."DEBTOR"

Link to comment
Share on other sites

$q = "SELECT estimate.job number, DEBTOR.NAMES, ESTIMATE.details1, debtor.salesrep, salesrep.name AS csr, estimate.due date, estimate.order no, estimate.qty1, estimate.qty2, estimate.qty3, estimate.qty4

FROM LIVEDATA_Dosrun.dbo.ESTIMATE, LIVEDATA_Dosrun.dbo.DEBTOR, LIVEDATA_Dosrun.dbo.SALESREP, LIVEDATA_Dosrun.dbo.INVOICE

WHERE ESTIMATE.JOB NUMBER = 53373 AND INVOICE.JOB NO = ESTIMATE.JOB NUMBER AND INVOICE.CSR RECNUM = SALESREP.DATAFLEX RECNUM ONE AND DEBTOR.AC NO = ESTIMATE.DEBTOR";

 

 

But I dont think those spaces in the Field Names will go through like that.

Link to comment
Share on other sites

$q = "SELECT estimate.job number, DEBTOR.NAMES, ESTIMATE.details1, debtor.salesrep, salesrep.name AS csr, estimate.due date, estimate.order no, estimate.qty1, estimate.qty2, estimate.qty3, estimate.qty4

FROM LIVEDATA_Dosrun.dbo.ESTIMATE, LIVEDATA_Dosrun.dbo.DEBTOR, LIVEDATA_Dosrun.dbo.SALESREP, LIVEDATA_Dosrun.dbo.INVOICE

WHERE ESTIMATE.JOB NUMBER = 53373 AND INVOICE.JOB NO = ESTIMATE.JOB NUMBER AND INVOICE.CSR RECNUM = SALESREP.DATAFLEX RECNUM ONE AND DEBTOR.AC NO = ESTIMATE.DEBTOR";

 

 

But I dont think those spaces in the Field Names will go through like that.

 

I did try it without the " and it didn't work because of the spaces in the field names.  Does PHP ever allow for spaces in the field names?

Link to comment
Share on other sites

It will be read better if you write it like this:

SELECT

"estimate"."job number",

"DEBTOR"."NAMES",

"ESTIMATE"."details1",

"debtor"."salesrep",

"salesrep"."name" AS "csr",

"estimate"."due date",

"estimate"."order no",

"estimate"."qty1",

"estimate"."qty2",

"estimate"."qty3",

"estimate"."qty4"

FROM

"LIVEDATA_Dosrun"."dbo"."ESTIMATE",

"LIVEDATA_Dosrun"."dbo"."DEBTOR",

"LIVEDATA_Dosrun"."dbo"."SALESREP",

"LIVEDATA_Dosrun"."dbo"."INVOICE"

WHERE

"ESTIMATE"."JOB NUMBER" = 53373 AND

"INVOICE"."JOB NO" = "ESTIMATE"."JOB NUMBER" AND

"INVOICE"."CSR RECNUM" = "SALESREP"."DATAFLEX RECNUM ONE" AND

"DEBTOR"."AC NO" = "ESTIMATE"."DEBTOR"

 

That does read much nicer...thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.