I want to share a MySQL connection, with other class within PHP, which held the query to do. So MySQL.php contains:
<?php
$user = 'username';
$passowrd = 'password';
$conn = new PDO('mysql:host=ip;dbname=DBName;port=3306',$user,$passowrd);
?>
And the php file, which I call MyLibrary.php contains:
<?php
include 'DB.php';
class Manager {
function jsonQuery() {
$response = array ();
$st = $conn->query ( "query");
$response ["results"] = array ();
foreach ( $st->fetchAll () as $row ) {
//my stuff with the query
}
$response ["success"] = 1;
echo json_encode ( $response );
}
}
$object = new Manager();
$object->jsonQuery();
?>
So how can I do ?