快捷搜索:

ACCESS数据库向MySQL快速迁移小程序,ajax轻量级聊

作者: w88官方网站手机版  发布:2019-09-30

@mysql_select_db("yourdatabase")

?>

4.聊天室页面:

or die("<p style='font-size:9pt;font-family:verdana;color:#803333;font-weight:bold'>No Database,</p>") ;
$odbc_table = "youroriginaltable" ; // The original table name in your ODBC database

?>

<?php
   require_once('dbconnect.php');
   db_connect();
   $msg = iconv("UTF-8","GB2312",$_GET["msg"]);
   $dt = date("Y-m-d H:i:s");
   $user = iconv("UTF-8","GB2312",$_GET["name"]);
   $sql="INSERT INTO chat(USERNAME,CHATDATE,MSG) " .
     "values(" . quote($user) . "," . quote($dt) . "," . quote($msg) . ");";
     echo $sql;
   $result = mysql_query($sql);
   if(!$result)
   {
    throw new Exception('Query failed: ' . mysql_error());
    exit();
   }
?>

这些年,本身为了将为铺面付出的二个消息保管种类从原先试运作的费用机器上(Windows NT IIS4.0 Access)迁移至一台实在的Linux服务器上(Apache1.3.12 PHP 4.03 MySQL 3.23.26),在那之中数据库中的几十二个表的从头到尾的经过迁移,开头让本身小费了有个别不利,从英特网也下载了有个别MySqL的客商软件只怕数据库管理软件,写得较好的软件均有数据迁移成效,但其搬迁格局除了三种,一种是选拔文件引进形式,此种情势在管理数据库中有和分隔符同样的字符时,会发生错误,越发是在拍卖ACCESS中的Memo字段,很轻巧出错,最终造成导出后的数量不是多了正是少了。而另一种帮助ODBC直接导入的功力较强,基本可无错误地导入各种表的内容,但非常不满,那不能够不是成立在ACCESS中表格的字段是希伯来语是才足以,如在ACCESS中字段是汉语名,常常也出错,不能够不辱职责导入。
为此笔者只得花了点时间写了四个小程序,用于将ACCESS数据库的开始和结果向MySQL迁移,经使用,效果还不易,特在此写出进献给各位一试或评判。
先概述一下应用办法,
1,将ACCESS的数据库建设构造贰个"system DSN";
2,依照ACCESS数据库中各表的名目,在MySQL中国建工业总会公司立相应的顺序空表;
3,运行fdlist.php;
4,运行import.php;
5,每运营一遍3,4步可迁移一个表,然后修改fdlist.php中的ACCESS源表名和MySQL中的目的表名,再运维3,4步,直至迁移全数的表,

  $link = mysql_connect("xxx.xxx.xxx.xxx", "databasename", "password")
            or die('不可能连接: ' . mysql_error());
  mysql_select_db("databasename") or die('未有您找到钦点数量库');
  return true;
}

chat.html

以下为 fdlist.php源程序

     
function set_chat_msg()
{

  1. 创建mysql数据库表:

<html>
<head>
<style type=text/css>
body,td,li,div,p,pre,a,b,h1,h2,h3,h4 {font-family:verdana;font-size:9pt;line-height : 18px;color:#a00000 }
</style>
</head>
<?
$dbconnection = @mysql_connect("yourmysqlserver", "mysqlaccount", "mysqlpassword")

     $sql="INSERT INTO chat(USERNAME,CHATDATE,MSG) " .
          "values(" . quote($user) . "," . quote($dt) . "," . quote($msg) . ");";

<?php
header("Content-Type:text/html;charset=gb2312");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
  header("Cache-Control: no-cache, must-revalidate");
  header("Pragma: no-cache");
   require_once('dbconnect.php');
   db_connect();
   $sql = "SELECT *, date_format(chatdate,'%Y年%m月%d日 %r') as cdt from chat order by ID desc limit 200";
   $sql = "SELECT * FROM (" . $sql . ") as ch order by ID";
   $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
   // Update Row Information
   $msg="<table border='0' style='font-size: 10pt; color: white; font-family: verdana, arial;'>";
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
   {
      $msg = $msg . "<tr><td>" . $line["cdt"] . " </td>" .
        "<td>" . $line["username"] . ": </td>" .
        "<td>" . $line["msg"] . "</td></tr>";
   }
   $msg=$msg . "</table>";
   echo $msg;
?>

or die ("can not connect to database server");

  date_default_timezone_set("Asia/Shanghai");

<?php
function db_connect()
{
 date_default_timezone_set("Asia/Shanghai");
 $link = mysql_connect("xxx.xxx.xxx.xxx", "databasename", "password")
      or die('不可能连接: ' . mysql_error());
 mysql_select_db("databasename") or die('未有您找到钦命数量库');
 return true;
}
function quote($strText)
{
  $Mstr = addslashes($strText);
  return "'" . $Mstr . "'";
}
function isdate($d)
{
  $ret = true;
  try
  {
    $x = date("d",$d);
  }
  catch (Exception $e)
  {
    $ret = false;
  }
  echo $x;
  return $ret;
}
?>

<?php
     require_once('dbconnect.php');

ajax接收函数chat_recv_ajax.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
";
<html xmlns="" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>聊天页面</title>
<script type="text/javascript">
var t = setInterval(function(){get_chat_msg()},5000);
//
// General Ajax Call
//
var oxmlHttp;
var oxmlHttpSend;
function get_chat_msg()
{
  if(typeof XMLHttpRequest != "undefined")
  {
    oxmlHttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    oxmlHttp = new ActiveXObject("Microsoft.XMLHttp");
  }
  if(oxmlHttp == null)
  {
    alert("浏览器不帮衬XML Http Request!");
    return;
  }
  oxmlHttp.onreadystatechange = get_chat_msg_result;
  oxmlHttp.open("GET",encodeURI("chat_recv_ajax.php"),true);
  oxmlHttp.send(null);
}
function get_chat_msg_result()
{
  if(oxmlHttp.readyState==4 || oxmlHttp.readyState=="complete")
  {
    if (document.getElementById("DIV_CHAT") != null)
    {
      document.getElementById("DIV_CHAT").innerHTML = oxmlHttp.responseText;
      oxmlHttp = null;
    }
    var scrollDiv = document.getElementById("DIV_CHAT");
    scrollDiv.scrollTop = scrollDiv.scrollHeight;
  }
}
function set_chat_msg()
{
  if(typeof XMLHttpRequest != "undefined")
  {
    oxmlHttpSend = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    oxmlHttpSend = new ActiveXObject("Microsoft.XMLHttp");
  }
  if(oxmlHttpSend == null)
  {
    alert("浏览器不帮助XML Http Request!");
    return;
  }
  var url = "chat_send_ajax.php";
  var strname="noname";
  var strmsg="";
  if (document.getElementById("txtname") != null)
  {
    strname = document.getElementById("txtname").value;
    document.getElementById("txtname").readOnly=true;
  }
  if (document.getElementById("txtmsg") != null)
  {
    strmsg = document.getElementById("txtmsg").value;
    document.getElementById("txtmsg").value = "";
  }
  url = "?name=" strname "&msg=" strmsg;
  oxmlHttpSend.open("GET",encodeURI(url),true);
  oxmlHttpSend.send(null);
}
function clickBtn(e)
 {
  if(window.event.keyCode==13)
  {
  var id=e.id;
  switch(id)
  {
   case "txtmsg":
   document.getElementById("Submit2").click();
   window.event.returnValue=false;
   break;
   }
  }
}
function fRandomBy(under, over){
switch(arguments.length){
case 1: return parseInt(Math.random()*under 1);
case 2: return parseInt(Math.random()*(over-under 1) under);
default: return 0;
}
}
function SetTxtName(){
var i=fRandomBy(10);
if(i==0)document.getElementById('txtname').value='无敌战神';
if(i==1)document.getElementById('txtname').value='令狐冲';
if(i==2)document.getElementById('txtname').value='南门吹雪';
if(i==3)document.getElementById('txtname').value='一流Mary';
if(i==4)document.getElementById('txtname').value='奥巴马';
if(i==5)document.getElementById('txtname').value='恐怖分子';
if(i==6)document.getElementById('txtname').value='聊斋奇女人';
if(i==7)document.getElementById('txtname').value='天朝?潘?;
if(i==8)document.getElementById('txtname').value='中500万了';
if(i==9)document.getElementById('txtname').value='神级奇葩';
if(i==10)document.getElementById('txtname').value='爱你不是两八天';
}
</script>
</head>
<body onload="SetTxtName();">
  <div style="border-right: black thin solid; border-top: black thin solid;
    border-left: black thin solid; border-bottom: black thin solid;
    background:#fff url('') repeat-x left top;
    height: 450px;width: 500px; ">
    <table style="width:100%; height:100%">
      <tr>
        <td colspan="2" style="font-weight: bold; font-size: 16pt; color: white; font-family: verdana, arial;
          text-align: center">
          聊天窗口--全球最大QQ聊天交友网址</td>
      </tr>
      <tr>
        <td colspan="2" style="font-weight: bold; font-size: 16pt; color: white; font-family: verdana, arial;
          text-align: left">
          <table style="font-size: 12pt; color: white; font-family: Verdana, Arial;border: white thin solid; ">
            <tr>
              <td style="width: 100px">
                名字:</td>
              <td style="width: 100px"><input id="txtname" style="width: 150px" type="text" name="name" maxlength="15" value="匿名" /></td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td style="vertical-align: middle;" valign="middle" colspan="2">
          <div style="width: 480px; height: 300px; border-right: white thin solid; border-top: white thin solid; font-size: 10pt; border-left: white thin solid; border-bottom: white thin solid; font-family: verdana, arial; overflow:scroll; text-align: left;" id="DIV_CHAT">
          </div>
        </td>
      </tr>
      <tr>
        <td style="width: 310px">
          <input id="txtmsg" style="width: 350px" type="text" name="msg" onkeydown="return clickBtn(this)"/></td>
        <td style="width: 85px">
          <input id="Submit2" style="font-family: verdana, arial" type="button" value="发送" onclick="set_chat_msg()"/></td>
      </tr>
      <tr>
        <td colspan="1" style="font-family: verdana, arial; text-align: center; width: 350px;">
          </td>
        <td colspan="1" style="width: 85px; font-family: verdana, arial; text-align: center">
        </td>
      </tr>
    </table>
  </div>
</body>
</html>
作用图如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";
<html xmlns="" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>聊天页面</title>
  
<script type="text/javascript">

create table chat( id bigint AUTO_INCREMENT,username varchar(20), chatdate datetime,msg varchar(500), primary key(id));
2.编纂建议连接数据库函数:
dbconnect.php

 

本文实例陈述了PHP mysql ajax轻量级聊天室完毕方式。分享给我们供大家参照他事他说加以考察,具体如下:
做了一个QQ聊天交友网址,想加个聊天的功能,于是做完用PHP做了简要又有力的聊天室

  1. 编写ajax发送和收取函数:
  1. 编排ajax发送和选用函数:
    ajax发送函数chat_send_ajax.php

<?php
header("Content-Type:text/html;charset=gb2312");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
   header("Cache-Control: no-cache, must-revalidate");
   header("Pragma: no-cache");
     require_once('dbconnect.php');

 

     $msg = iconv("UTF-8","GB2312",$_GET["msg"]);
     $dt = date("Y-m-d H:i:s");
     $user = iconv("UTF-8","GB2312",$_GET["name"]);

ajax接收函数chat_recv_ajax.php

</head>
<body onload="SetTxtName();">
    
    <div style="border-right: black thin solid; border-top: black thin solid;
        border-left: black thin solid; border-bottom: black thin solid;
        background:#fff url('') repeat-x left top;
        height: 450px;width: 500px; ">
        <table style="width:100%; height:100%">
            <tr>
                <td colspan="2" style="font-weight: bold; font-size: 16pt; color: white; font-family: verdana, arial;
                    text-align: center">
                    聊天窗口--举世最大QQ聊天交友网址</td>
            </tr>
            <tr>
                <td colspan="2" style="font-weight: bold; font-size: 16pt; color: white; font-family: verdana, arial;
                    text-align: left">
                    <table style="font-size: 12pt; color: white; font-family: Verdana, Arial;border: white thin solid; ">
                        <tr>
                            <td style="width: 100px">
                                名字:</td>
                            <td style="width: 100px"><input id="txtname" style="width: 150px" type="text" name="name" maxlength="15" value="匿名" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="vertical-align: middle;" valign="middle" colspan="2">
                    <div style="width: 480px; height: 300px; border-right: white thin solid; border-top: white thin solid; font-size: 10pt; border-left: white thin solid; border-bottom: white thin solid; font-family: verdana, arial; overflow:scroll; text-align: left;" id="DIV_CHAT">
                    </div>
                </td>
            </tr>
            <tr>
                <td style="width: 310px">
                    <input id="txtmsg" style="width: 350px" type="text" name="msg" onkeydown="return clickBtn(this)"/></td>
                <td style="width: 85px">
                    <input id="Submit2" style="font-family: verdana, arial" type="button" value="发送" onclick="set_chat_msg()"/></td>
            </tr>
            <tr>
                <td colspan="1" style="font-family: verdana, arial; text-align: center; width: 350px;">
                    </td>
                <td colspan="1" style="width: 85px; font-family: verdana, arial; text-align: center">
                </td>
            </tr>
        </table>
    </div>
</body>
</html>

     db_connect();
    
     $sql = "SELECT *, date_format(chatdate,'%Y年%m月%d日 %r') as cdt from chat order by ID desc limit 200";
     $sql = "SELECT * FROM (" . $sql . ") as ch order by ID";
     $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    
     // Update Row Information
     $msg="<table border='0' style='font-size: 10pt; color: white; font-family: verdana, arial;'>";
     while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
     {
           $msg = $msg . "<tr><td>" . $line["cdt"] . " </td>" .
                "<td>" . $line["username"] . ": </td>" .
                "<td>" . $line["msg"] . "</td></tr>";
     }
     $msg=$msg . "</table>";
    
     echo $msg;

ajax发送函数chat_send_ajax.php

 

var t = setInterval(function(){get_chat_msg()},5000);

效果:

function db_connect()
{

2.编写制定建议连接数据库函数:

1. 创建mysql数据库表:create table chat( id bigint AUTO_INCREMENT,username varchar(20), chatdate datetime,msg varchar(500), primary key(id));

     $result = mysql_query($sql);
     if(!$result)
     {
        throw new Exception('Query failed: ' . mysql_error());
        exit();
     }

图片 1

          echo $sql;

     db_connect();

4.聊天室页面:

chat.html

<?php

dbconnect.php

    if(typeof XMLHttpRequest != "undefined")
    {
        oxmlHttpSend = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
       oxmlHttpSend = new ActiveXObject("Microsoft.XMLHttp");
    }
    if(oxmlHttpSend == null)
    {
       alert("浏览器不援助XML Http Request!");
       return;
    }
   
    var url = "chat_send_ajax.php";
    var strname="noname";
    var strmsg="";
    if (document.getElementById("txtname") != null)
    {
        strname = document.getElementById("txtname").value;
        document.getElementById("txtname").readOnly=true;
    }
    if (document.getElementById("txtmsg") != null)
    {
        strmsg = document.getElementById("txtmsg").value;
        document.getElementById("txtmsg").value = "";
    }
   
    url = "?name=" strname "&msg=" strmsg;
    oxmlHttpSend.open("GET",encodeURI(url),true);
    oxmlHttpSend.send(null);
}
function clickBtn(e)
  {
   if(window.event.keyCode==13)
   {
    var id=e.id;
    switch(id)
    {
     case "txtmsg":
      document.getElementById("Submit2").click();
      window.event.returnValue=false;
      break;
     }
   }
}
function fRandomBy(under, over){
switch(arguments.length){
case 1: return parseInt(Math.random()*under 1);
case 2: return parseInt(Math.random()*(over-under 1) under);
default: return 0;
}
}
function SetTxtName(){
var i=fRandomBy(10);
if(i==0)document.getElementById('txtname').value='无敌战神';
if(i==1)document.getElementById('txtname').value='令狐冲';
if(i==2)document.getElementById('txtname').value='南门吹雪';
if(i==3)document.getElementById('txtname').value='一流Mary';
if(i==4)document.getElementById('txtname').value='奥巴马';
if(i==5)document.getElementById('txtname').value='恐怖分子';
if(i==6)document.getElementById('txtname').value='聊斋奇女生';
if(i==7)document.getElementById('txtname').value='天朝?潘?;
if(i==8)document.getElementById('txtname').value='中500万了';
if(i==9)document.getElementById('txtname').value='神级奇葩';
if(i==10)document.getElementById('txtname').value='爱你不是两四日';
}
</script>

 
?>

function quote($strText)
{
    $Mstr = addslashes($strText);
    return "'" . $Mstr . "'";
}

做了一个QQ聊天交友网址,想加个聊天的成效,于是做完用PHP做了简便又有力的聊天室

function isdate($d)
{
   $ret = true;
   try
   {
       $x = date("d",$d);
   }
   catch (Exception $e)
   {
       $ret = false;
   }
   echo $x;
   return $ret;
}

    if(typeof XMLHttpRequest != "undefined")
    {
        oxmlHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
       oxmlHttp = new ActiveXObject("Microsoft.XMLHttp");
    }
    if(oxmlHttp == null)
    {
        alert("浏览器不援助XML Http Request!");
       return;
    }
   
    oxmlHttp.onreadystatechange = get_chat_msg_result;
    oxmlHttp.open("GET",encodeURI("chat_recv_ajax.php"),true);
    oxmlHttp.send(null);
}
    
function get_chat_msg_result()
{
    if(oxmlHttp.readyState==4 || oxmlHttp.readyState=="complete")
    {
        if (document.getElementById("DIV_CHAT") != null)
        {
            document.getElementById("DIV_CHAT").innerHTML =  oxmlHttp.responseText;
            oxmlHttp = null;
        }
        var scrollDiv = document.getElementById("DIV_CHAT");
        scrollDiv.scrollTop = scrollDiv.scrollHeight;
    }
}

 

//
// General Ajax Call
//
     
var oxmlHttp;
var oxmlHttpSend;
     
function get_chat_msg()
{

本文由www.w88985.com发布于w88官方网站手机版,转载请注明出处:ACCESS数据库向MySQL快速迁移小程序,ajax轻量级聊

关键词: www.w88985.c