Home >Backend Development >PHP Tutorial >PHP连接Mysql的实例

PHP连接Mysql的实例

WBOY
WBOYOriginal
2016-06-23 14:29:04938browse

 



connect . php title >
head >

/* PHP手册中的PHP连接Mysql的实例 */
php
     /*  连接选择数据库  */    
 
  $link   =   mysql_connect ( " mysql_host " ,   " mysql_user " ,   " mysql_password " )        or  die ( " Could not connect " );  
   print   " Connected successfully " ;    
  mysql_select_db ( " my_database " ) or  die ( " Could not select database " );
     /*  执行 SQL 查询  */     
 
  $query   =   " SELECT * FROM my_table " ;   
  $result   =   mysql_query ( $query ) or  die ( " Query failed " );  
 
   /*  在 HTML 中打印结果  */   
 
  print   "

\n " ;   
  while  ( $line   =   mysql_fetch_array ( $result ,  MYSQL_ASSOC))
 {       
    print   " \t\n " ;       
    foreach  ( $line   as   $col_value ) 
   { 
      print   " \t\t\n " ;   
   }       
    print   " \t\n " ;    
  }    
  print   "
$col_value
\n " ;
 
   /*  释放资源  */
    
  mysql_free_result ( $result );    
 
  /*  断开连接  */    
 
  mysql_close ( $link );
?>
 
body >

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn