PHP sample code using the Mysqli object

Source: Internet
Author: User
Tags php sample code

1234567891011121314151617181920212223242526272829303132333435363738394041 <?php  //连接参数  $host="localhost";  $user="root";  $pwd="111111";  $db="test";    $mysqli =new mysqli($host,$user,$pwd,$db); //实例化一个mysqli对象,并打开一个连接    if(mysqli_connect_errno()){ //检查是否可以正确打开数据库    echo "<font color=‘red‘>unable to connect!</font>";  }    $SQL_SELECT_SYMBOLS="select * from symbols";    if($result=$mysqli->query($SQL_SELECT_SYMBOLS)){     if($result->num_rows>0){                echo ‘<table cellpadding="10" border="1">‘;        echo ‘<tr><th>id</th><th>country</th><th>animal</th><th>cname</th></tr>‘;        while($arr=$result->fetch_array()){            echo "<tr>";            echo "<td>".$arr[0]."</td>";            echo "<td>".$arr[1]."</td>";            echo "<td>".$arr[2]."</td>";            echo "<td>".$arr[3]."</td>";            echo "</tr>";        }         echo "</table>";    }   else{    echo "记录未找到!";   }    $result->close(); //释放记录集所占用的内存  }  else{    echo "error in query:$query.".$mysqli->error;  }  $mysqli->close(); //关闭数据库连接?>

PHP sample code using the Mysqli object

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.