亚洲狼人综合,本道综合精品,在线看福利影,国产亚洲精品久久久玫瑰,日韩欧美精品在线观看,日韩在线国产,欧美乱码一区二区三区

php 5.6.19連接數(shù)據(jù)庫(kù)

2018-03-14 14:42:06 csdn  點(diǎn)擊量: 評(píng)論 (0)
php5 3以上版本不建議使用mysql_connect ,mysql_query等函數(shù),轉(zhuǎn)而使用mysqli系列(improved)。這是連接數(shù)據(jù)庫(kù)及查詢數(shù)據(jù)的兩個(gè)例子。[ph

php5.3以上版本不建議使用mysql_connect ,mysql_query等函數(shù),轉(zhuǎn)而使用mysqli系列(improved)。這是連接數(shù)據(jù)庫(kù)及查詢數(shù)據(jù)的兩個(gè)例子。

 

[php] view plain copy
 
  1. <?php  
  2. require 'conn.php';  //$link=mysqli_connect($host,$user,$pass,$database);  
  3.   
  4. $query="select * from user_info";  
  5. if($result=mysqli_query($link,$query)){  
  6.     echo "query was successfully executed.".'<br>';  
  7.     while($row=mysqli_fetch_assoc($result)){  
  8.           
  9.         echo $row["name"]." ".$row["surname"].'<br>';  
  10.             }  
  11.     mysqli_free_result($result);  
  12. }  
  13. else{  
  14.     echo "the query is not executed.".'<br>';  
  15. }  
  16. mysqli_close($link);  
  17. ?>  

 

[php] view plain copy
 
  1. <?php  
  2. /** 
  3.  * Created by PhpStorm. 
  4.  * User: KPF 
  5.  * Date: 2016/6/28 
  6.  * Time: 17:21 
  7.  */  
  8. require_once('json.php');  
  9. /*class Db{ 
  10.     static private $_instance; 
  11.     public function __construct() 
  12.     { 
  13.  
  14.     } 
  15. }*/  
  16. $connect=mysqli_connect('127.0.0.1','root','606','tcb');  
  17. /* check connection */  
  18. if (mysqli_connect_errno()) {  
  19.     printf("Connect failed: %s\n", mysqli_connect_error());  
  20.     exit();  
  21. }  
  22.   
  23. $sql="select * from user_info";  
  24.   
  25. $result=mysqli_query($connect,$sql);  
  26. if (!$result) {  
  27.     printf("Error: %s\n", mysqli_error($connect));  
  28.     exit();  
  29. }  
  30.   
  31. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);  
  32. printf("%s %s %s\n"$row['user_name'], $row['user_pass'],$row['user_faceurl']);  
  33. /*$row=array(); 
  34. while($row=mysqli_fetch_assoc($result)){ 
  35.     $row[]=$row; 
  36. } 
  37. if($row){ 
  38.     return Response::show(200,'首頁(yè)數(shù)據(jù)返回成功',$row); 
  39. }*/  
  40. mysqli_close($connect);  
  41. ?>  


 

 

大云網(wǎng)官方微信售電那點(diǎn)事兒

責(zé)任編輯:售電衡衡

免責(zé)聲明:本文僅代表作者個(gè)人觀點(diǎn),與本站無(wú)關(guān)。其原創(chuàng)性以及文中陳述文字和內(nèi)容未經(jīng)本站證實(shí),對(duì)本文以及其中全部或者部分內(nèi)容、文字的真實(shí)性、完整性、及時(shí)性本站不作任何保證或承諾,請(qǐng)讀者僅作參考,并請(qǐng)自行核實(shí)相關(guān)內(nèi)容。
我要收藏
個(gè)贊
?