I am using PHP PDO to connect to my database and run some querys to then use the query return on some forms.
That is, I have a select where it is populated by the values ??coming from the query.
I created two functions to connect to the database and data, but I wanted to know if I can create a global variable because I am using the "New PDO" .
/** Conecta com as impressas **/
function impressoras()
{
$PDO2 = new PDO('mysql:host=localhost;dbname=ti','root','xxx');
$PDO2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
global $stmt;
$stmt = $PDO2->prepare("SELECT * FROM league");
$stmt->execute();
$result = $stmt->fetchAll();
return $result;
echo json_encode($user_arr);
}
function carrefour()
{
$PDO3 = new
PDO('mysql:host=localhost;dbname=ti','root','xxx');
$PDO3->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
global $stmt;
$stmt = $PDO3->prepare("SELECT * FROM lol");
$stmt->execute();
$result = $stmt->fetchAll();
return $result;
echo json_encode($user_arr);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…