MSSQL Query issue in PHP and querying text data
Couple of options from the comments on the mssql_query()
manual page
SELECT CAST(field1 AS TEXT) AS field1 FROM table
- Chang the version in
/etc/freetds.conf
from 4.2 to 8.0 (if the PHP server is *nix) - Avoid
SELECT *
queries
Plenty more if you search ntext
on that page.
SQL Server Query not working when executed from PHP
Messages
Changed database context to XXXXXXX
Changed language setting to YYYYYYY
are not error messages. They are informational messages and should be ignored by applications. PHP can be configured to ignore it.
Severity Levels: https://msdn.microsoft.com/en-us/library/ms164086.aspx
PHP Settings:
1) php.ini changes:
mssql.min_error_severity = 11
mssql.min_message_severity = 11
or
2) by executing
mssql_min_error_severity(11);
just before execution of mssql_query()
http://php.net/manual/en/function.mssql-min-error-severity.php
UPDATE:
3) The trigger should have
set nocount on;
at the top of code, just after:
AS
BEGIN
This will prevent sending multiple informational messages (like "xx rows affected") to the application.
SQL Server fetch data php
You have a syntax error in the generated T-SQL Statment - missing spaces before FROM
and WHERE
. The generated statement is SELECT form_adres, form_sehir, form_adsoyadFROM databasename.omg_user.ie_formWHERE form_no='15275'
. Fix the statement and always check the result from mssql_query()
execution:
<?php
...
// declare the SQL statement that will query the database
$query = " SELECT form_adres, form_sehir, form_adsoyad";
$query .= " FROM databasename.omg_user.ie_form";
$query .= " WHERE form_no='15275'";
// execute the SQL query and return records
$result = mssql_query($query, $dbhandle);
if ($result === false) {
echo "Error (mssql_query): ".mssql_get_last_message();
exit;
}
...
?>
Text data getting cut off when returned from DB
If you are counting characters in Management Studio, try:
SELECT LEN(Content), DATALENGTH(Content) FROM dbo.myTable;
Does that still show 4096? I bet not.
I don't think you want to cast as TEXT. I assume you are using NTEXT because you may have Unicode characters. Converting to TEXT will eliminate any double-byte characters and actually change your data. Perhaps you could try this from your application:
SELECT CONVERT(NVARCHAR(MAX), Content) FROM dbo.myTable;
And don't rely on Management Studio's output to be a testament to what's actually in the database. It is truncated by default, and limited to a fixed maximum even if you change the defaults (different character counts depending on results to text or results to grid). If you want to know how much data is in a column, ask SQL Server (like I did above), not Management Studio.
Why is my SQL Server query failing?
Check that you're querying the right database or schema.
software.software_dbo.ApplicationInfo
means:
- a database named
software
- a schema named
software_dbo
- likely this is the problem. Likely isdbo
on your SQL Server. - a view/table named
ApplicationInfo
Perhaps check what the value of DBO
, amongst the other arguments, is in this statement: $connect = mssql_connect(DBSERVER, DBO, DBPW)
Related Topics
Woocommerce Cart - Conditional Items Categories Validation
PHP Object of Class Dateinterval Could Not Be Converted to String
PHP - Get the Size of a Directory
How to Detect and Handle MySQL Warnings with PHP
Pdo Multiple Fetching of Same Query
Check for Session Timeout in Laravel
Use Curl with Sni (Server Name Indication)
PHP $Stmt->Num_Rows Doesnt Work by Prepared Statements
Get_Instance() in Codeigniter: Why Assign It to a Variable
Expose "Use" Classes to Included File
Minimum Cart Amount for Specific Product Categories in Woocommerce
Sort Array by Length and Then Alphabetically
How to Create a Logfile in PHP
Variable Variables Pointing to Arrays or Nested Objects
PHP String in Array Only Returns First Character
How to Run Composer from Anywhere
Forbidden :You Don't Have Permission to Access /Phpmyadmin on This Server