Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('better_mysqli.php'); // can be obtained from: http://pastebin.com/ATyzLUfK
- // == Instantiate the mysqli database object (aka open the database) ==
- $mysqli = new better_mysqli('your_server', 'your_user', 'your_pass', 'your_db_name');
- if (mysqli_connect_errno()) {
- error_log(sprintf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()));
- exit;
- }
- // == select example ==
- unless( $sth = $mysqli->select('select * from table1 where col1=? and col2=?', $row, array('col1_placeholder_value', 'col2_placeholder_value'), $debug_level=0, $verbose_debug_output)){
- if($debug_level>0){ echo $verbose_debug_output;}
- // .. do your error handling here
- }
- while($sth->fetch()){
- echo $row['col1'] .', '. $row['col2'] .', and '. $row['col_etc'] .' are accessed like that.<br>';
- }
- // == insert example ==
- $statement = "insert into table1 (col1, col2, date_col, col_etc) values (?, ?, NOW(), ?)";
- unless( $mysqli->insert($statement, array('col1_insert_value', 'col2_insert_value', 'col_etc_value'), $debug_level=0, $verbose_debug_output, $id_of_new_record) ){
- if($debug_level>0){ echo $verbose_debug_output;}
- // .. do your error handling here
- }
- // == update example ==
- unless($mysqli->update("update table1 set col1=? where col2=?", array('col1_value', 'col2_value'), $debug_level=0, $verbose_debug_output) ){
- if($debug_level>0){ echo $verbose_debug_output;}
- // .. do your error handling here
- }
- // == delete example ==
- unless( $mysqli->delete("delete from table1 where col1=? where col2=?", array('col1_value', 'col2_value'), $debug_level=0, $verbose_debug_output) ){
- if($debug_level>0){ echo $verbose_debug_output;}
- // .. do your error handling here
- }
- // in all cases statements are prepared just once and cached so if you reuse any statement the already prepared statement handle is automatically used
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement