PHP--Connect to MySQL Database

Source: Internet
Author: User

-----022-mysql.php-----

1<! DOCTYPE html>234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">5<title>MySQL</title>67<body>8MySQL9<pre style= "font-family: Microsoft ya black; Font-size:14pt ">Ten<?PHP One     //Absolute Path! Absolute path! Absolute path!  A     $con= @mysql_connect("localhost", "root", "root") or die("Unable to connect to database"); -     mysql_select_db("World",$con); -     $sql= "Select code, name, population from country ORDER by population DESC LIMIT 5"; the     $result=mysql_query($sql,$con); -     Echo"Resources queried:",$result, "\ n"; -     Echo"Number of results queried:", @mysql_numrows($result), "\ n"; -     Echo"The third row of data:",Mysql_result($result, 0, "code"), "",Mysql_result($result, 0, "name"), "",Mysql_result($result, 0, "population"), "\ n"; +  -     Mysql_data_seek($result, 0);//pointer-homing +     Echo"<b>mysql_fetch_row query data:</b>", "\ n"; A      while(List($a,$b,$c) =Mysql_fetch_row($result)){ at         Echo $a, "---",$b, "---",$c, "\ n"; -     } -  -     Mysql_data_seek($result, 0);//pointer-homing -     Echo"&LT;B&GT;MYSQL_FETCH_ASSOC query data:</b>", "\ n"; -      while($s=Mysql_fetch_assoc($result)){ in         Var_export($s); -     } to     Echo"\ n"; +  -     Mysql_data_seek($result, 0);//pointer-homing the     Echo"<b>mysql_fetch_array query data:</b>", "\ n"; *      while($s=Mysql_fetch_array($result,mysql_num)) { $         Echo $s[0], "",$s[1], "",$s[2]/100000000, "billion \ n";Panax Notoginseng     } -  the     Mysql_data_seek($result, 0);//pointer-homing +     Echo"<b>mysql_fetch_object query data:</b>", "\ n"; A      while($s=Mysql_fetch_object($result)){ the         foreach($s  as $key=$value){ +             printf("%s=>%-15s",$key,$value); -             //echo $key, "= =", $value, "\ t"; $         } $         Echo"\ n"; -     } -     Echo"Error message:",Var_export(Mysql_error()), "\ n"; the     Echo"Error code:",Mysql_errno(), "\ n"; -?>Wuyi</pre> the</body> -

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.