beridius
asked on
php mssql connection
I have a connection to MSSQL database which I use mssql_query and mssql_fetch_assoc
I have problem when I use a join in the statement.
when just connecting to a single table in the SQL part
If i do not put the [sqldatabase].[dbo].[table name]
I get an internal error
but I am stuck with is statement work in sql builder but no in php
name]
I have problem when I use a join in the statement.
when just connecting to a single table in the SQL part
SELECT id, sName, iStatus
FROM [SQL01].[dbo].[KPIDay]
If i do not put the [sqldatabase].[dbo].[table
I get an internal error
but I am stuck with is statement work in sql builder but no in php
SELECT Lead_T.sName AS Expr1, LeadSource_T.sName, TransferClient_T.sName AS Client, TransferSubscription_T.sName AS Subs, LeadTransfer_T.zXUpdtdWhn AS Date,
LeadTransfer_T.zXUpdtdBy AS [Updated By], TransferClient_T.id
FROM TransferClient_T INNER JOIN
LeadSource_T INNER JOIN
LeadTransfer_T ON LeadSource_T.id = LeadTransfer_T.FKiSourceID INNER JOIN
Lead_T ON LeadTransfer_T.FKiLeadID = Lead_T.id ON TransferClient_T.id = LeadTransfer_T.FKiClientID INNER JOIN
TransferSubscription_T ON LeadTransfer_T.FKiSubscriptionID = TransferSubscription_T.id
WHERE (LeadTransfer_T.zXUpdtdWhn BETWEEN CONVERT(DATETIME, '2012-10-29 00:00:00', 102) AND CONVERT(DATETIME, '2012-10-29 23:59:59', 102)) AND
(TransferClient_T.id = 27)
ORDER BY TransferClient_T.zXUpdtdWhn, Date, LeadSource_T.sName DESC
not sure where I need the [sqldatabase].[dbo].[table
can you provide the exact error you are getting.
Have you selected the database before you query?
mssql_select_db("SQL01");
$results = mssql_query("SELECT id, sName, iStatus FROM KPIDay");
mssql_select_db("SQL01");
$results = mssql_query("SELECT id, sName, iStatus FROM KPIDay");
ASKER
I dont have a mssql_select_db I put that in now and come back to you
ASKER
I just get a blank screen no errors but when I try and echo a column I dont get anything
$query_Recordset1 = "SELECT Lead_T.sName AS Expr1, LeadSource_T.sName, TransferClient_T.sName AS Client, TransferSubscription_T.sName AS Subs, LeadTransfer_T.zXUpdtdWhn AS Date,
LeadTransfer_T.zXUpdtdBy AS [Updated By], TransferClient_T.id
FROM TransferClient_T INNER JOIN
LeadSource_T INNER JOIN
LeadTransfer_T ON LeadSource_T.id = LeadTransfer_T.FKiSourceID INNER JOIN
Lead_T ON LeadTransfer_T.FKiLeadID = Lead_T.id ON TransferClient_T.id = LeadTransfer_T.FKiClientID INNER JOIN
TransferSubscription_T ON LeadTransfer_T.FKiSubscriptionID = TransferSubscription_T.id
WHERE (LeadTransfer_T.zXUpdtdWhn BETWEEN CONVERT(DATETIME, '2012-10-29 00:00:00', 102) AND CONVERT(DATETIME, '2012-10-29 23:59:59', 102)) AND
(TransferClient_T.id = 27)
ORDER BY TransferClient_T.zXUpdtdWhn, Date, LeadSource_T.sName DESC
";
mssql_select_db('LM',$conn);
$Recordset1 = mssql_query($query_Recordset1) or die();
$row_Recordset1 = mssql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mssql_num_rows($Recordset1);
not sure where I am going wrong
Add something inside die(), like die("Problem querying!");
ASKER
I put print print var_dump(mssql_get_last_me ssage());
and get
string(39) "Invalid object name 'TransferClient_T'."
and get
string(39) "Invalid object name 'TransferClient_T'."
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have just checked the connection to that table I put [databasename].[dbo].[tabl ename] and its working now thanks guys for all your help