mysqli::query
(mysqli_query) Perform a query on the database
query()
/ mysqli_query()
function executes a query on the database.
Perform a query on the database:
<?php $mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ; // Check the connection if ( $mysqli -> connect_errno ) { echo "Failed to connect to MySQL: " . $mysqli -> connect_error ; exit ( ) ; } // Execute query if ( $result = $mysqli -> query ( "SELECT * FROM Persons" ) ) { echo "Returned rows are: " . $result -> num_rows ; // Release the result set $result -> free_result ( ) ; } $mysqli -> close ( ) ; ?>
Perform a query on the database:
<?php $con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( mysqli_connect_errno ( ) ) { echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ; exit ( ) ; } // Execute query if ( $result = mysqli_query ( $con , "SELECT * FROM Persons" ) ) { echo "Returned rows are: " . mysqli_num_rows ( $result ) ; // Release the result set mysqli_free_result ( $result ) ; } mysqli_close ( $con ) ; ?>