长沙北大青鸟作者:科泰校区KnightE
<?php /* Connect to a MySQL server */ $link = mysqli_connect( 'localhost', /* The host to connect to */ 'user', /* The user to connect as */ 'password', /* The password to use */ 'world'); /* The default table to query */ if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error()); exit; } /* Send a query to the server */ if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) { print("Very large cities are:n"); /* Fetch the results of the query */ while( $row = mysqli_fetch_assoc($result) ){ printf("%s (%s)n", $row['Name'], $row['Population']); } /* Destroy the result set and free the memory used for it */ mysqli_free_result($result); } /* Close the connection */ mysqli_close($link); ?>
Very large cities are:
Mumbai (Bombay) (10500000)
Seoul (9981619)
São Paulo (9968485)
Shanghai (9696300)
Jakarta (9604900)
<?php /* Connect to a MySQL server */ $mysqli = new mysqli('localhost', 'user', 'password', 'world'); if (mysqli_connect_errno()) { printf("Can't connect to MySQL Server. Errorcode: %sn", mysqli_connect_error()); exit; } /* Send a query to the server */ if ($result = $mysqli->query('SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) { print("Very large cities are:n"); /* Fetch the results of the query */ while( $row = $result->fetch_assoc() ){ printf("%s (%s)n", $row['Name'], $row['Population']); } /* Destroy the result set and free the memory used for it */ $result->close(); } /* Close the connection */ $mysqli->close(); ?>
注:本文章为原创文章,版权归文章作者与超越PHP网站所有,未经本站同意,禁止任何商业转载。非盈利网站及个人网站转载请注明出处,谢谢合作!