我在PHP执行一条SQL语句,执行不了,可我把它打印出来,直接在PHPMYADMIN中执行,就可以执行
这是怎么回事
哪位高人帮帮忙

解决方案 »

  1.   

    如果你把echo 出来的SQL放在phpmyadmin中去执行,并且成功的话,只能说你php的mysql没有配置好!
    看看是配置参数,还是mysql连接,执行等等的哪儿块出问题了还有就是如果执行不了,应该会有错误提示的啊,楼主要是把提示贴出来,肯定很快就会解决的如果没有错误提示,那肯定PHP的mysql操作对象就没建成功,或根本没有数据更新
      

  2.   

    <?php
    set_time_limit(0);  $page = (int)$_REQUEST["page"];
      $page = $page>1?$page:1;
      $num = 30;  //每次导入100条数据
      $temp = ($page-1)*$num;
      $mssql_db= 'Dbtest1'; //odbc 数据库
      $mssql_user = 'sa'; //odbc 数据库用户名
      $mssql_pwd = 'admin'; //odbc 数据库用户密码
      $mssql_server = 'localhost';  $db_name = 'Dbtest'; //SKYUC PHP数据库
      $db_user = 'admin'; //SKYUC PHP数据库用户名
      $db_pwd = 'admin';//SKYUC PHP数据库用户密码
      */
      $msconn = odbc_connect("Driver={SQL Server};Server=$mssql_server;Database=$mssql_db",$mssql_user,$mssql_pwd) OR die("数据连接出错");
      $count =  odbc_exec($msconn, "SELECT  count(softID) C FROM PE_Soft INNER JOIN PE_DownServer ON PE_Soft.ChannelID = PE_DownServer.ChannelID where PE_Soft.Status = 3 and PE_Soft.Deleted = 0 and PE_Soft.channelid in (1002,1003,1004,1005,1006,1007,1008,1010,1013)" );
      while(odbc_fetch_row($count))
      {
       $count = odbc_result($count,'C');
      }
      $nums = ($num*$page*100)/($count);
      $nums = round($nums,2); 
      echo "共".$count."条数据,已经导入".$nums."%";
      $cur= odbc_exec($msconn, "SELECT  TOP $num  PE_Soft.*,PE_DownServer.ServerUrl FROM PE_Soft INNER JOIN PE_DownServer ON PE_Soft.ChannelID = PE_DownServer.ChannelID where PE_Soft.Status = 3 and PE_Soft.Deleted = 0 and PE_Soft.channelid in (1002,1003,1004,1005,1006,1007,1008,1010,1013) AND SoftID NOT IN (SELECT TOP $temp SoftID FROM PE_Soft order by SoftID ASC) " );
      $num_row=0;
      $conn=mysql_pconnect("localhost", $db_user, $db_pwd);
      @mysql_select_db($db_name,$conn) or die("无法连接到数据库,请与管理员联系!");
      mysql_query("SET character_set_connection='utf8', character_set_results='utf8', character_set_client=binary");
      echo "<b>数据库链接成功!</b>" ."<br>";
      while(odbc_fetch_row($cur))
      {
    $num_row++;
       $contentid = odbc_result($cur, 'SoftID');
       $catid = odbc_result($cur, 'classid');
       $title = odbc_result($cur, 'softname');
       $keywords = odbc_result($cur, 'keyword');
       $decription = odbc_result($cur, 'SoftIntro');
       $decription = htmlspecialchars($decription);
       $decription = str_replace('"','\\"',$decription);
       $decription = str_replace("'",'\\"',$decription);
    $decription = str_replace(".",' ',$decription);
    $readpoint = odbc_result($cur, 'InfoPoint');
    $copytype = $readpoint > 0?'收费版':'免费版';
    $filesize = odbc_result($cur, 'SoftSize');
    $downserver = odbc_result($cur, 'ServerUrl');
       $downurls = odbc_result($cur, 'DownloadUrl');
       $downurls = str_replace('@@@',"$title|$downserver",$downurls);;
      
    $sqls = 'SELECT COUNT(*) FROM phpcms_content'. " WHERE contentid='".$contentid."'";   
    $res = mysql_query($sqls,$conn);
    $row = mysql_fetch_row($res);
    if($row[0]>0)
        {
    echo "<font color=red>资料:$title 已存在,跳过!</font><br>";  
        }
        else
        {
    $sql1 ="INSERT INTO table1 (contentid, template, content, version, classtype, language, copytype, systems, stars, filesize, downurl, downurls, groupids_view, readpoint) VALUES ($contentid , ' ', '$decription', ' ', '国产软件', '简体中文', '$copytype', 'Win2000/WinXP/Win2003', '★★★☆☆', $filesize, ' ', '$downurls', 1, '$readpoint');";
    $sql = "INSERT INTO table2 ( contentid, catid, typeid, areaid, title, style, thumb, keywords, description, posids, url, listorder, status, userid, username, inputtime, updatetime, searchid, islink, prefix) VALUES
    ( $contentid, $catid, 0, 0, '$title', ' ', ' ', '$keywords', ' ', 0, 'show.php?contentid=$contentid', 0, 99, 1, 'phpcms', '1235631364', '1235631364', 0, 0, ' ');";

    //echo $sql;
    if(mysql_query($sql,$conn))
    {
      echo "正在导入……资料:<font color=blue>" .$title."</font><font color=green>"."</font>……";
    }
    else 
    {
       echo "$sql<br>";
    }
    if(mysql_query($sql1,$conn))
    {
       echo "正在导入……下载:<font color=blue>" .$title."</font><font color=green>"."</font>……<font color=green>OK!</font><br>";
    }
    else
    {
    echo $sql1;
       break;
       echo "正在导入……下载:<font color=blue>" .$title."</font><font color=green>"."</font>……<font color=red>FAIL!</font><br>";
    } }
    if($num_row>=$num)
    {
    $page++;
    echo "<script>window.setTimeout(\"window.location.href='?page=$page'\",1000);</script>"; }
      }
    ?>
    SQL语句打印出来在PHPMYADMIN中是可以执行的
    而且这中间也只有部分不能执行,大部分是没有问题的
      

  3.   

    朋友,这个问题以前我也遇到过。这个是你的字符没有转成mysql的校对字符,
    你可以在链接后加上mysql_query("set names utf-8")等类似的语句,就成功了。
      

  4.   

    show variables like 'character%';
    查看编码如果是gb2312,改为gbk就可以解决繁体问题!