首页 > 数据库技术 > 详细

php执行sql语句打印结果

时间:2018-03-30 19:28:13      阅读:497      评论:0      收藏:0      [点我收藏+]
 1      $dbname=DB_NAME;
 2         $host=DB_HOST;
 3         $port=DB_PORT;
 4         $user =DB_USER;
 5         $password=DB_PWD;
 6 
 7         $mysqli = new \mysqli($host, $user, $password, $dbname,$port);
 8 
 9         //$sql="explain select * from k_user ";
10         $sql="select * from k_user limit 1";
11         //$sql="desc k_score_log";
12         //$sql="ALTER TABLE `k_user` ENGINE=MyISAM;";
13         //$sql="ALTER TABLE `k_user` ENGINE=InnoDB;";
14         $result = $mysqli->query($sql);
15 
16         if($result){
17             if(is_object($result)){
18                 echo <div style="margin:0 auto;width: 1000px;height: 800px;"><div style="width: 1000px;overflow:auto">;
19                 echo "<table style=‘border-color: #efefef;‘ width=‘1000px‘ border=‘1px‘ cellpadding=‘5px‘ cellspacing=‘0px‘>";
20                 $show_title=true;
21                 $colums=0;
22                 while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
23                     $header_str="";
24                     $content_str="";
25                     foreach($row as $key=>$value){
26                         if($show_title){
27                             $colums++;
28                             $header_str.="<td>$key</td>";
29                         }
30                         $content_str.="<td>$value</td>";
31                     }
32 
33                     if(!empty($header_str)){
34                         echo "<tr style=‘font-weight: bold‘>$header_str</tr>";
35                     }
36                     echo "<tr>$content_str<tr>";
37                     $show_title=false;
38                 }
39                 echo "</table>";
40                 echo "</div>";
41                 echo "<div style=‘margin-top:20px;float:right;font-weight:bold;‘>共计".$result->affected_rows."".$colums."列</div>";
42                 echo </div>;
43                 $result->close();
44             }else{
45                 echo True;
46             }
47 
48         }
49 
50         $mysqli->close();

 

php执行sql语句打印结果

原文:https://www.cnblogs.com/saonian/p/8677744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!