2
I’m researching the use of Mysqli and have seen many articles, but each one always has some particularities about the development pattern, my question has anyone defined a pattern? For example something that can be followed with best practices?
For example an insert code from this article here: PHP Mysqli Basic Usage (select, Insert & update)
real_escape_string('P1234').'"';
$product_name = '"'.$mysqli->real_escape_string('42 inch TV').'"';
$product_price = '"'.$mysqli->real_escape_string('600').'"';
//MySqli Insert Query
$insert_row = $mysqli->query("INSERT INTO products (product_code, product_name, price) VALUES($product_code, $product_name, $product_price)");
if($insert_row){
print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'
';
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
?>
And in that other article: How to Use PHP Improved Mysqli Extension
$v1="'" . $conn->real_escape_string('col1_value') . "'";
$sql="INSERT INTO tbl (col1_varchar, col2_number) VALUES ($v1,10)";
if($conn->query($sql) === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
} else {
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
}
Ferinha, I am more PDO-compliant to Mysqli and PSR-compliant.. Another thing, in what concerns design partern, in my last developed applications, I thought it necessary to use Active Record, there is a lot in google about it
– Samuel Diogo
see this video: https://www.youtube.com/watch?v=OGzK1uFBJd0 I think you can help...
– Samuel Diogo
Pattern in which direction and than?
– rray
Hello @rray, thanks for asking, how to follow a pattern for CRUD, I have read many articles and always have a lot of different things.
– adventistapr
Post examples of this difference in articles
– Lucas
Your question is quite incomplete. State what pattern you are saying and which usage finality
– user21494