欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

达梦数据库链接PHP技术说明

程序员文章站 2022-06-02 20:05:33
...
在 php.ini 文件中 配置DM:

[dm]
dm.allow_persistent = 1
dm.max_persistent = -1
dm.max_links = -1
dm.default_host = localhost
dm.default_db = SYSTEM
dm.default_user = SYSDBA
dm.default_pw = SYSDBA
dm.connect_timeout = 10
dm.defaultlrl = 4096
dm.defaultbinmode = 1
dm.check_persistent = ON
dm.port = dm12345



<?php
  $dbhost = 'localhost';
  $dbuser = 'SYSDBA';
  $dbpass = 'ABCDE54321';
  $dbname = 'BOOKSHOP';
  $connect = dm_connect($dbhost, $dbuser, $dbpass);

  if($connect)
  {
    echo '成功连接到达梦数据库系统';
  }
  else
  {
    echo '连接达梦数据库系统失败';
    echo dm_error();
    exit;
  }

  dm_select_db($dbname) or die("select DB error.");

  $sql = "INSERT INTO MYTEST.TABLE1 (SNAME, NAGE, BGENDER) VALUES ('姓名', 80, true)";
  dm_query($sql);

  if (dm_affected_rows()>0)
   echo "Insert OK.";
  else
    echo "Insert failed.";

  $sql = "select * from MYTEST.TABLE1";
  $result = dm_query($sql);

  echo "<br>";
  while($row=dm_fetch_assoc($result))
  {
    echo $row["NID"] . "&nbsp;&nbsp;&nbsp;" . $row["SNAME"] . "&nbsp;&nbsp;&nbsp;" . $row["NAGE"]. "&nbsp;&nbsp;&nbsp;" . $row["BGENDER"] . "<br>";
  }

  /* 释放资源 */
  dm_free_result($result);

  /* 断开连接 */
  dm_close($connect);
相关标签: 服务器