Advertisement
MatheusMouraHT

Exemplo conexão com PDO - CloudSql

Sep 19th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2.  
  3. echo "Conectando...";
  4. $host = "mysql:unix_socket=/cloudsql/ID_INSTANCIA;dbname=NOME_BANCO";
  5. $user = "USUARIO";
  6. $password ="SENHA";
  7.  
  8. try{
  9.   // create a PDO connection with the configuration data
  10.   $conn = new PDO($host, $user, $password);
  11.  
  12.   // display a message if connected to database successfully
  13.   if($conn){
  14.     echo "Connected database successfully!";
  15.   }
  16.  
  17.  } catch (PDOException $e) {
  18.   // report error message
  19.   echo $e->getMessage();
  20.  }
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement