I need some help with convert these MySQL line to Db2, I’m not sure which one to use.
Lines I need convert are mysql_select_db('P510F');
And is it right to add p510f in there? Or is it meant for something else to be there?
<?php if(isset($_POST['update'])) { $dbhost = 'IASP'; $dbuser = 'bo'; $dbpass = 'cul8rabgb1'; $conn = db2_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: '); } $emp_id = $_POST['emp_id']; $emp_salary = $_POST['emp_salary']; $sql = "UPDATE p510F ". "SET P510INF = $emp_salary ". "WHERE P510KEY = $emp_id" ; mysql_select_db('P510F'); $retval = db2_exec( $sql, $conn ); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfullyn"; db2_close($conn); }else { ?>
break
<form method = "post" action = "<?php $_PHP_SELF ?>"> <table width = "400" border =" 0" cellspacing = "1" cellpadding = "2"> <tr> <td width = "100">Employee ID</td> <td><input name = "emp_id" type = "text" id = "emp_id"></td> </tr> <tr> <td width = "100">Employee Salary</td> <td><input name = "emp_salary" type = "text" id = "emp_salary"></td> </tr> <tr> <td width = "100"> </td> <td> </td> </tr> <tr> <td width = "100"> </td> <td> <input name = "update" type = "submit" id = "update" value = "Update"> </td> </tr> </table> </form> <?php } ?>
Advertisement
Answer
Could you try something like this;
$database = 'P510F'; $user = 'db2inst1'; $password = 'password'; $hostname = 'localhost'; $port = 50000; $conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" . "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;"; $conn = db2_connect($conn_string, '', ''); if(! $conn ) { die('Could not connect: '. db2_conn_error()); } $emp_id = $_POST['emp_id']; $emp_salary = $_POST['emp_salary']; $sql = "UPDATE p510KEY ". "SET P510INF = $emp_salary ". "WHERE P510KEY = $emp_id" ; $stmt = db2_prepare($conn, $sql); if ($stmt) { $result = db2_execute($stmt); if (!$result) { echo "exec errormsg: " .db2_stmt_errormsg($stmt); } echo "Updated data successfullyn"; } else { echo "exec errormsg: " . db2_stmt_errormsg($stmt); } db2_close($conn); }else { ?>