Open a connection to a MySQL Server in php5
Change the default database for the connection in php5
Send a MySQL query in php5 or Perform queries against the database in php5
Fetch a result row as an associative array in php5.
Note: Fieldnames returned from this function are case-sensitive.
Fetch a result row as an associative array, a numeric array, or both in php5.
Note: Fieldnames returned from this function are case-sensitive.
Get the ID generated from the previous INSERT operation or Returns the id (generated with AUTO_INCREMENT) used in the last query in php5.
Get the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query in php5.
Get one row from a result-set and returns it as an enumerated array in php5 .
Get number of rows in result in php5.
Close a previously opened database connection in php5 .
Returns a string with the error description from previous MySQL operation in php5. "" if no error occurred.
Return an error code from the last connection error, if any in php5.Zero if no error occurred.
Fetch rows from a result-set, then free the memory associated with the result in php5. No return value.
<?php $link = mysqli_connect('host_name', 'user_name', 'password','db_name') or die('Could not connect: ' . mysqli_error()); echo 'Connected successfully'; if(mysqli_connect_errno($link)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_select_db('database_name') or die('Could not select database'); //changing the default database $query = 'SELECT * FROM table_name'; $result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error()); // performing SQL query // Printing results in HTML echo "\n"; while($row = mysqli_fetch_assoc($result )){ echo "\t\n"; foreach ($row as $col_value) { echo "\t\t\n"; echo "$col_value\n"; } echo "\t\n"; } mysqli_free_result($result); // Free resultset mysqli_close($link); // Closing connection ?>