php - how to escape string in mysqli -


in old mysql() code, escape string, did this:

t.teacherusername = '".mysql_real_escape_string($teacherusername)."' 

i changing code mysqli, want know sure , safe, escape string in mysqli below:

t.teacherusername = '".mysqli_real_escape_string($teacherusername)."' 

also connect mysqli database below:

$username="xxx"; $password="xxx"; $database="xxx";  mysqli_connect('localhost',$username,$password);  mysqli_select_db($database) or die( "unable select database"); 

all have done change mysql mysqli, correct?

update:

is correct way connect database using mysqli:

$username="xxx"; $password="xxx"; $database="mobile_app";  $mysqli = new mysqli("localhost", $username, $password, $database);  if (mysqli_connect_errno()) {     printf("connect failed: %s\n", mysqli_connect_error());     exit(); } 

your use of function incorrect.

you must use mysqli link resource returned mysqli_connect first parameter mysqli_real_escape_string.

example:

$username="xxx"; $password="xxx"; $database="xxx";  $my = mysqli_connect('localhost',$username,$password);  mysqli_select_db($my, $database) or die( "unable select database");  $t->teacherusername = "'" . mysqli_real_escape_string($my, $teacherusername). "'"; 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -