Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function mySQLi_connection(){
- $hostName = "localhost";
- $userName = "admin";
- $password = "admin";
- $databaseName = "db_name";
- $mysqli = new mysqli($hostName, $userName, $password, $databaseName);
- if($mysqli->connect_errno > 0){
- die('Unable to connect to database [' . $db->connect_error . ']');
- }
- return $mysqli;
- }
- function getEmpNamebyID($id){
- $empname = NULL;
- echo "Inside getEmpNamebyID() with id = $id";
- $mysqli = mySQLi_connection();
- $qry = "SELECT `empname` FROM `employee_details` WHERE `EMP_ID` =?";
- if ($stmt2 = $mysqli ->prepare($qry)) {
- if($stmt2 === false) {
- trigger_error('Wrong SQL: ' . $qry . ' Error: ' . $mysqli->errno . ' ' . $mysqli->error, E_USER_ERROR);
- }
- if (!$stmt2->bind_param("s", $id)) {
- echo "Binding parameters failed: (" . $stmt2->errno . ") " . $stmt2->error;
- }
- if (!$stmt2->execute()) {
- echo "Execute failed: (" . $stmt2->errno . ") " . $stmt2->error;
- }
- if (!$stmt2->bind_result($empname)) {
- echo "Binding output parameters failed: (" . $stmt2->errno . ") " . $stmt->error;
- }
- }
- echo $empname;
- return $empname;
- }
- echo getEmpNamebyID(95);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement