简体   繁体   English

使用 db2 更新数据库

[英]Update database with db2

I need some help with convert these MySQL line to Db2, I'm not sure which one to use.我需要一些帮助来将这些 MySQL 行转换为 Db2,我不确定要使用哪一个。

Lines I need convert are mysql_select_db('P510F');我需要转换的行是mysql_select_db('P510F'); And is it right to add p510f in there?在那里添加 p510f 是否正确? 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 successfully\n";
        
        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
     }
  ?>

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 successfully\n";

   } else {
         echo "exec errormsg: " . db2_stmt_errormsg($stmt);
   }
   db2_close($conn);

     }else {
        ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM