php 连接mysql

WBOY
Release: 2016-06-23 13:13:14
Original
868 people have browsed it




新建网页



   
                    $link=@mysql_pconnect('127.0.0.1','root','');
            mysql_select_db('mysql',$link);
            $query="SELECT Host,User FROM user";
            $result=mysql_query($query,$link);
            //获取的字段
            while($filed=mysql_fetch_field($result)){
                echo $filed->name."
";            

            }
            echo mysql_affected_rows($link);
            //获取行
            while($row=mysql_fetch_row($result)){
                echo $row[0].$row[1].'
';
            }

            //$query="CREATE DATABASE my_db";
            /*$sql = "CREATE TABLE Persons (
                FirstName varchar(15),
                LastName varchar(15),
                Age int
            )";*/
            /*$sql = "CREATE TABLE Persons (personID int NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(personID),
        FirstName varchar(15),
        LastName varchar(15),
        Age int
        )";  设置主键
            */

        /*mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");*/

        /*$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "
";
  }

        */
  /*查找
    $result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "
";
  }

  */
            mysql_close($link);
                ?>
   
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template