frameworks - is it possible to write plain PHP code inside SLIM .php files -


i beginner in php , no knowledge of slim framework. have add insert query, shown below, in .php file of slim project.

$username = "myuser"; $password = "mypw"; $hostname = "localhost";   $date = date("y/m/d h:i:s");  function get_client_ip() {   $ipaddress = '';   if (getenv('http_client_ip'))       $ipaddress = getenv('http_client_ip');   else if(getenv('http_x_forwarded_for'))       $ipaddress = getenv('http_x_forwarded_for');   else if(getenv('http_x_forwarded'))       $ipaddress = getenv('http_x_forwarded');   else if(getenv('http_forwarded_for'))       $ipaddress = getenv('http_forwarded_for');   else if(getenv('http_forwarded'))       $ipaddress = getenv('http_forwarded');   else if(getenv('remote_addr'))       $ipaddress = getenv('remote_addr');   else       $ipaddress = 'unknown';    return $ipaddress; }  $ipadr = get_client_ip();  //connection database $dbhandle = mysql_connect($hostname, $username, $password)        or die("unable connect mysql");  $selected = mysql_select_db("mydb",$dbhandle)      or die("unable select mydb");  mysql_query("insert `my_table` (`user-ip`,`user-date`) values ('$ipadr','$date')");  mysql_close($dbhandle); 

can me how this? possible mix plain php code slim framework code? great.

yes, can that. put code within function , call function within route callable.

note mysql functions old , no longer available php 7, should change them use either mysqli or pdo.


Comments