Q: which method is responsible for sending query to database?

 Q: which method is responsible for sending query to database?

Ans: In PHP, the method for sending a query to a database is typically mysqli_query() or PDO::query().

These methods are used to execute SQL statements on a database connection.

$result = mysqli_query($conn, $sql);

OR

$stmt = $conn->query($sql); $result = $stmt->fetchAll();

It takes two arguments, the first is the database connection link, and the second is the SQL query. It returns a result set on success or FALSE on failure.

It's important to notice that PDO is an extension that provides a data-access abstraction layer, it can be used with multiple database like MySQL, PostgreSQL, SQLite and others, while mysqli is specific for MySQL.


No comments:

Post a Comment