扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年10月21日
关键字:
<?php //检索用户的输入 $animalName = $_POST['animalName']; //连接到数据库 $connect = mysqli_connect( 'localhost', 'username', 'password', 'database' ); if ( !$connect ) exit( 'connection failed: ' . mysqli_connect_error() ); //创建一个查询语句源 $stmt = mysqli_prepare( $connect,"SELECT intelligence FROM animals WHERE name = ?" ); if ( $stmt ) { //把替代绑定到语句上 mysqli_stmt_bind_param( $stmt, "s", $animalName ); //执行该语句 mysqli_stmt_execute( $stmt ); //检索结果... mysqli_stmt_bind_result( $stmt, $intelligence ); // ...并显示它 if ( mysqli_stmt_fetch( $stmt ) ) { print "A $animalName has $intelligence intelligence.\n"; } else { print 'Sorry, no records found.'; } //清除语句源 mysqli_stmt_close( $stmt ); } mysqli_close( $connect ); ?> |
<?php $animalName = $_POST['animalName']; $mysqli = new mysqli( 'localhost', 'username', 'password', 'database'); if ( !$mysqli ) exit( 'connection failed: ' . mysqli_connect_error() ); $stmt = $mysqli->prepare( "SELECT intelligence FROM animals WHERE name = ?" ); if ( $stmt ) { $stmt->bind_param( "s", $animalName ); $stmt->execute(); $stmt->bind_result( $intelligence ); if ( $stmt->fetch() ) { print "A $animalName has $intelligence intelligence.\n"; } else { print 'Sorry, no records found.'; } $stmt->close(); } $mysqli->close(); ?> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。