0% found this document useful (0 votes)
3 views1 page

PHP Database Functions Notes

This document provides notes on commonly used PHP functions for interacting with MySQL databases using MySQLi, including connection, query execution, and data retrieval. It includes code examples for connecting to a database, executing insert and select queries, counting rows, and closing the connection. Important notes emphasize checking connection success, ensuring queries match table structure, and closing the connection after use.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

PHP Database Functions Notes

This document provides notes on commonly used PHP functions for interacting with MySQL databases using MySQLi, including connection, query execution, and data retrieval. It includes code examples for connecting to a database, executing insert and select queries, counting rows, and closing the connection. Important notes emphasize checking connection success, ensuring queries match table structure, and closing the connection after use.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PHP Database Functions (MySQLi) – Notes

These are commonly used PHP functions for interacting with MySQL databases using MySQLi.

Function Purpose
mysqli_connect() Connect to database
mysqli_query() Execute SQL query
mysqli_fetch_assoc() Fetch row as associative array
mysqli_num_rows() Count rows in result
mysqli_close() Close connection

Connection Example
<?php
$conn = mysqli_connect("localhost", "root", "", "db_name");
?>

Insert Query
<?php
mysqli_query($conn, "INSERT INTO table VALUES ('1','John')");
?>

Select Query
<?php
$result = mysqli_query($conn, "SELECT * FROM table");

while($row = mysqli_fetch_assoc($result)){
echo $row['name'];
}
?>

Count Rows
<?php
$count = mysqli_num_rows($result);
?>

Close Connection
<?php
mysqli_close($conn);
?>

Important Notes
1. Always check connection success.
2. Queries must match table structure.
3. Close connection after use.

You might also like