Jump to content

MySQLi código mais eficiente?


Moneybag
 Share

Go to solution Solved by HappyHippyHippo,

Recommended Posts

Boas Pessoal

Qual dos seguintes códigos é mais "limpo"/eficiente na vossa opinião em mysqli :

function get_employee($mysqli, $i_id) {
$query = "SELECT * FROM tbl_employee WHERE id = '". $i_id ."'";
if($result = $mysqli->query($query)){
 $row = $result->fetch_row();
}
$result->close();
return $row;
}

function get_email($mysqli, $i_id) {
   if ($stmt = $mysqli->prepare("SELECT email FROM tbl_employee WHERE id = ? LIMIT 1")) {
    $stmt->bind_param('i', $i_id);
    $stmt->execute();    // Execute the prepared query.
    $stmt->store_result();

    // get variables from result.
    $stmt->bind_result($db_email);
    $stmt->fetch();
   }
   $stmt->close();
   return $db_email;
}

Apesar das dua funcções retornarem diferentes tipos de dados , existem algo que possa melhorar em algum desses 2 códigos?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.