Mysql error in connection

<?php
   function getMysqlConnection($host,$user,$pass,$database){
     global $mysqli;
     global $Mysqlerror;
       $mysqli = new mysqli('$host','$user','$pass','$database');
  if(empty($mysqli->connect_errorno) == false){
      $Mysqlerror = "true";
  }else{
      $Mysqlerror = "false";
  } }
   ?>

I created the function described above that implements the connection with the given mysql user credentials and I implemented this function using

<?php
require 'myFunc.php';
getMysqlConnection("localhost", "wronguser","wrongpass" ," test");
 echo $Mysqlerror;
 ?>

Although I used the wrong password and username, Mysqlerror is false. I also used or was able, the function did not happen

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /opt/lampp/htdocs/mysite/myFunc.php on line 5

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in /opt/lampp/htdocs/mysite/myFunc.php on line 5

I restarted the flashlight, as usual, it showed

Starting XAMPP for Linux 1.8.0...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
Warning: World-writable config file '/opt/lampp/etc/my.cnf' is ignored
XAMPP: Starting ProFTPD...
/opt/lampp/share/lampp/alladdons: line 23: /opt/lampp/share/addons/: is a directory
XAMPP for Linux started.

There is a problem with my code or with my server. How to fix it?

+5
source share
2 answers

The problem with this line.

$ mysqli = new mysqli ('$ host', '$ user', '$ pass', '$ database');

Change it to

$ mysqli = new mysqli ($ host, $ user, $ pass, $ database);

In PHP, variables in single quotes are not interpolated with their values.

PHP

+3

mysql first..provide username password (wat u mysql). w3schools.com tizag.com

0

All Articles