Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqli_real_escape_string within Yii 2 using DAO or something else?

Tags:

php

yii

yii2

I'm using Yii 2 and about to starting working with databases for the first time within it and was wondering if Yii 2 had something else you should use to prepare data for the database such as the standard mysqli_real_escape_string function or should I just use that?

I'm not using prepared statements, I'm accessing the database via their database access objects and wondering how I go about escaping the data I pass to it?

I found the quoteValue method but it's included within what Yii calls Connection represents a connection to a database via PDO. so I wasn't sure if it was the right method to use?

like image 846
Brett Avatar asked Dec 03 '22 18:12

Brett


1 Answers

As you said, you should use quoteValue.

If your dao component name is db, then you should simply try :

$quoteValue = \Yii::$app->db->quoteValue($value);
like image 147
soju Avatar answered Dec 06 '22 09:12

soju