What is the PDO equivalent of:
mysqli_stat($dbConn);
P.S. I use it to (get a message to) make sure I am connected
The connection remains active for the lifetime of that PDO object. To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted—you do this by assigning null to the variable that holds the object.
The PDO represents a connection between PHP and a database server. The PDOStatement represents a prepared statement and, after the statement is executed, an associated result set. The PDOException represents an error raised by PDO.
Fetch data from a result set by calling one of the following fetch methods: To return a single row from a result set as an array or object, call the PDOStatement::fetch method. To return all of the rows from the result set as an array of arrays or objects, call the PDOStatement::fetchAll method.
I cannot get credit for this answer. Someone posted the answer, but he/she latter deleted the entry.
Here's the (saved archived)
answer to your question:
$status = $conn->getAttribute(PDO::ATTR_CONNECTION_STATUS);
$pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS) always return "127.0.0.1 via TCP/IP" even if i stop mysqld, to use:
if ($pdo->getAttribute(PDO::ATTR_SERVER_INFO)=='MySQL server has gone away')
{
$pdo=new PDO('mysql:host=127.0.0.1;port=3306;dbname=mydb;charset=UTF8', 'root', '', array(PDO::ATTR_PERSISTENT=>true));
}
you can use
$name = $conn->getAttribute(PDO::ATTR_DRIVER_NAME);
Connections and Connection management
PDO::getAttribute
PDO::getAttribute
- Retrieve a database connection attribute
http://www.php.net/manual/en/pdo.getattribute.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With