+ 1

PHP Class/Function with SQL

Does anybody know if this code will work? I mean, if the connection doesn't work, will the function return the echo, and if it does work, will it return the mysqli_result object? Thanks! <?php class Query{ var $host="localhost"; var $db_user="user"; var $password="pass"; var $db="data_base"; function sql_query($query){ $con=mysqli_connect($this->host,$this->db_user,$this->pass,$this->db); if (mysqli_connect_errno()) { echo 'Error al conectar con base de datos: '.mysqli_connect_errno(); } else{ $retval=mysqli_query($con,$query); return $retval; } } } ?>

20th Mar 2017, 12:53 AM
Matias Schiaffino
Matias Schiaffino - avatar
1 Réponse
0
I don't personally use mysqli. I use mysql with " or die ()" statements after. But, from what I can tell this should work as you expect it to.
26th Mar 2017, 8:01 PM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar