1
Hello,
I had some problems with a code on SELECT
...
example:
SELECT dados FROM banco WHERE CPF='$CPF' // com o código assim estava dando alguns erros pois o bd era em SQL e o Servidor windows.
The solution was:
SELECT CAST(CAST([dados] AS VARCHAR(8000)) AS TEXT) AS dados FROM dbo.banco WHERE CPF='$CPF;
I was wondering if there’s another simpler solution that doesn’t require such extensive code...
type, if I want to detail the table fields and use 4 fields, it only works if I put the CAST
where is nVARCHAR
.
Note: I can not change in the bank nVARCHAR
to just VARCHAR
.
Thank you in advance!
It would be nice to report the error.
– Caffé
Which driver are you using to connect to SQL Server in PHP? I think you need to set the maximum size allowed for text (reference), otherwise the values are truncated.
– bfavaretto
No mistake buddy, just wanted a better solution... because the code gets too long...
– Ursones
"with the code so was giving some errors" (
SELECT dados FROM banco WHERE CPF='$CPF'
). Is there an error or is there not? If not, what’s the problem of using it like this (without CAST)?– Caffé
It is that making the query with CAST requires a lot of the memory used by php(I think that’s it) and in some cases as the code gets very extensive, ends up presenting the following "Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 2184 bytes) in /home/Storage/6/C4/26/amb8/public_html/user/data.php on line 105" ... So I wanted a cleaner Cód too, i understand the basics of php so I’m complicating myself a little to explain rsrs ...
– Ursones
I still don’t understand why you don’t use
SELECT dados FROM banco WHERE CPF='$CPF'
– Caffé
Which driver you can connect mssql, sqlsrv, PDO to?
– rray
Caffé use Cód this way no funfa... because in SQL the fields are in nVARCHAR and not only in VARCHAR... rray I am using "mssql" ... The Locaweb attendant gave me the following information: "You should then improve your select, which as you can notice makes several conversions and pulls several records, thus causing exhaustion...
– Ursones
@Ursones "in SQL the fields are in nVARCHAR and not only in VARCHAR" - That’s no reason to
SELECT dados FROM banco WHERE CPF='$CPF'
not work. What is missing is to say which unwanted behavior or error was obtained with this query so that it was forced to use conversions (CAST); thus we would help solve the real problem instead of the problem caused by a strange conversion (the TEXT type is deprecated in MSSQL). I was able to explain?– Caffé
@Caffé Truth friend, vlw the explanation, in the end I changed php.ini pq the configuration was not authorizing the use of mssql...
mssql.compatability_mode = Off
, I switched toOn
And I didn’t have toCAST
... Vlw for the tips and patience with me haha...– Ursones
@Ursones No problem! You’re welcome.
– Caffé
@Ursones, put the procedure you did as a response, so it can help other people with the same problem :).
– rray
Okay and thank you all :D
– Ursones