What is the recommended alternative to using mysql_fetch_array with MYSQL_ASSOC in PHP?
The recommended alternative to using mysql_fetch_array with MYSQL_ASSOC in PHP is to use the mysqli_fetch_assoc function. This function fetches a row from a result set as an associative array. It provides a more secure and efficient way to retrieve data from a MySQL database in PHP.
// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");
// Query the database
$result = $mysqli->query("SELECT * FROM table");
// Fetch data as associative array
while ($row = $result->fetch_assoc()) {
// Process data here
}
// Close connection
$mysqli->close();
Keywords
Related Questions
- What are some best practices for handling absolute paths in PHP to avoid vulnerabilities?
- What are best practices for organizing data retrieved from a database in PHP using fetch_object()?
- How can English naming conventions improve code readability and maintainability, and what impact can incorrect naming have on the development process?