'fi' displaying incorrectly in database - php

I have a mySQL database with the following
e.g.
Microeconomics.
The ‘theory of the ï¬rm’
or:
Resource allocation modiï¬cations.
For some reason, the text that has been input (through CKEditor), has been changed so any instances of fi are in the database as 'ï¬'. I believe this is something to do with HTML entities. The text (I believe) was copy-pasted from a word document, which could be part of the problem.
How do I change (in PHP or mySQL) all instances of 'ï¬' into fi? When rendered as a PDF by TCPDF, it shows a ? (e.g. financial = ?nancial, significant = signi?cant)
Thanks in advance.

This statement will correct all the false instances for the column that contains the 'ï¬'
Update table Set
column = replace(column, 'ï¬', 'fi')

Related

Sentrifugo - PHP can't display Unicode (Vietnamese) correctly

I'm using Sentrifugo open source HRM software. When I insert Unicode text data, the page displays it properly, except for some tables like this.
For example, this website shows it incorrecty: Nguyá»�n Thá»� Hà Linh, but when I point at that to show the title or click View detail, the text displays it correctly: Nguyễn Thị Hà Linh.
The database also changes to utf8.
I appended two lines above in to application.ini.
I also use SET NAME UTF 8:
$mysqlPDO = new PDO('mysql:host='.SENTRIFUGO_HOST.';dbname='.SENTRIFUGO_DBNAME.'',SENTRIFUGO_USERNAME, SENTRIFUGO_PASSWORD,array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$mysqlPDO->exec("set names utf8");
All columns in every table are utf8.
Please see these images:
- Database
Column
Somewhere on web show well
Somewhere show symbol (like ASCII)

How to do case sensitive where() 'in' match in yii2 with mysql database

I've got a hashtags table in my mysql db, with a string(512) column called tag. I want to do a case sensitive search using Yii2's ActiveQuery, like this:
$expTags = ['one','two','three'];
Hashtag::find()->where(["IN","tag",$expTags])->select(["id"]);
In mysql, this usually means prefixing BINARY outside every value, or prefixing the column name. I tried both, I even tried "IN BINARY", nothing worked.
How to do this? I need case sensitive search, and I don't want to modify the table / column collation just to do this.
previous answer here got it pretty close:
$expTags = ['one','two','three'];
Hashtag::find()->where(["BINARY IN","tag",$expTags])->select(["id"]);
BINARY IN (used as operator) causes a syntax error (for mysql at least)
Hashtag::find()->where('BINARY tag in(:tag)', ['tag'=> $expTags])->select(["id"]);
and this hits the pdo problem of binding an array to a single param
this will work however:
Hashtag::find()->where(['BINARY(`tag`)' => $expTags])->select(["id"]);
you can try this:
$expTags = ['one','two','three'];
Hashtag::find()->where(["BINARY IN","tag",$expTags])->select(["id"]);
or
Hashtag::find()->where('BINARY tag in(:tag)', ['tag'=> $expTags])->select(["id"]);

how could I change the type of column in redbeanphp?

I am using the RedBeanPHP, I have a string of numbers, is it possible to store it like the string, not a double type? My example is next, and it doesn't work:
$participant = R::dispense('participants');
$participant->setMeta("participants.number","string");
$participant->number = $number;
R::store($participant);
Redbean check attribute given value to set the right type for the column, I would recommend you to work with freeze option off every time, but, when you need to change something, you just turn it on. I mean, just turn freeze on when you really need to perform some change on you table, for ex:
// the false param will disable db changes
R::setup('dns', 'user', 'pass', false);changes (freeze option)
//...
//... let's imagine you have some code here
//...
R::freeze(false);
$participant = R::dispense('participants');
$participant->number = 'intert any string'; // need to set field to string type
R::store($participant);
R::freeze(true);
$participant->number = '99.99';
R::store($participant);
I know it is not the best thing ever, but you just have to turn it on when you need to change something on DB structure. Essentially, in production environment you should always turn it off
RedBean will automatically try to guess the right column type for the data you provide. However, it will never shrink a column, (for example from TEXT to INTEGER), only widen (for example from INTEGER to TEXT).
If it's important for you that the database column is TEXT during development, you could therefore insert a string and delete it again to "trick" RedBean into making the column type TEXT.
For example, put this code snippet into some type of initialization script:
$participant = R::dispense('participants');
$participant->number = 'not a number';
R::store($participant);
R::trash($participant);
// Column 'participants.number' is now of type TEXT
As I mentioned earlier, RedBean will never shrink the column to INTEGER even if you never insert anything else than number strings again.
On the other hand, if it's not critical to you during development, you could just freeze the database before deploying to production and manually change the column type to TEXT in your database manager.

PHP/mySQL get_file_contents and update the column

I have a mySQL db table. One of the table columns contains URLs which point to different xml files on a remote server.
My goal is to read each URLs info and write the xml content into another column on the same record (line) respectively.
In my PHP code, I am able to get the URL correctly from mySQL database and I am able to get the XML content on remote server into a variable correctly.
But the issue is while I write the content to my table line by line. Some XML columns got update correctly and some XML columns are empty.
I am pretty sure each time the variable got content correctly because I am able to print out each individual content on screen.
Why are some content updating the column and some don't. All the XML strings have the same format. If I copied that content and updated the mysql table manually, it successfully wrote into the table.
At beginning I thought it was time issue so I add enough sleep time for my PHP code. it does't help. then I suspected my db datatype, so I changed the XML
column data type from VCHAR to TEXT and even LONGTEXT. it does't help either. Does any one have a clue?
part of my php code below...
$result = mysqli_query($con,"SELECT url_txt FROM mytable ");
//work with result line by line:
while($row = mysqli_fetch_array($result)) {
echo $url_content = file_get_contents($row['url_txt']);
//debug line below *******************************/
echo $URL=$row[url_txt];
//debug line above********************************/
mysqli_query($con,"UPDATE mytable SET xml_info='$url_content' where url_txt = '$URL' ");
}
Maybe try converting your XML to a native array and working with it that way:
$array = json_decode(json_encode(simplexml_load_string($url_content)),TRUE);

How to display 'text' data correctly with Microsoft ODBC driver for Linux? Currently displaying as random characters

I am trying to display the contents of a field in a MS SQL database, the data type of which is 'text'. When I connect to the database with MS Excel on a PC the value looks something like:
Shipped on the: 18/10/12 Toll IPEC Connote Number: XXX XXX XXXX
When I connect to the database with PHP using the Microsoft ODBC driver for Linux, the output of the text field will display random characters, which are slightly different each time I run the exact same script. Here is what it output the last four times:
Xisep)!ØwXment.class.php))
5isep)!ment.class.php))
µ}isep)!Ø}ment.class.php))
t)!!Owner_IDt)Ø©Ø8
Not sure where it's getting the 'ment.class.php' bit from. That looks like the end of the name of one of my classes, but not one that is included in this particular script. Is the driver broken or what? All other data types (int, varchar, datetime etc) seem to display correctly, the problem only seems to happen with this one text field.
Here is the code:
<?php
require('ConnectWise.inc.php');
$config = new CW_Config;
// Connect to database
$dbcnx = odbc_connect("ConnectWise", $config->db_username, $config->db_password);
// Query database
$query = "select * from Billing_Log where Invoice_Number = '24011'";
$result = odbc_exec($dbcnx, $query);
while ($row = odbc_fetch_array($result)) {
echo $row['Top_Comment'] . "\n";
}
odbc_close($dbcnx);
Here is the output of my last few attempts:
\3ȶä!!¶äY!
öÈö§!!ö§Y!
&Èö×!!ö×Y!
Looks like you're getting an overflow. For some reason SQL is passing the length of your text field as 0, which to SQL means "long" but to PHP means "I dont know" and so PHP is showing whatever is in its memory at the location its expecting data (or something like that - any PHP experts care to explain?).
I've seen this with varchar(max) before but not text. (Converting to) Text is normally the way to fix it. So maybe I'm wrong.
Hope this is of some help. Im not a PHP developer, I just have to use it occasionally, and this sounds much like a painful experience I've gone through before :)

Categories