Undefined variable $conn

Hello, in web host have config.php from my database. On my computer have local server. When from php file on my computer i try to connect with databasse on web host with connfig file on web host somting wrong…

config.php on web host

<?php
	
	$servername = 'host';
	$username = 'user';
	$password = 'pass';
	$dbname = 'db';

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname); 
set_time_limit(500);
// Check connection
if ($conn->connect_error) {
  die("Проблем с интернета или достъпа ! ");
}
?>

Playlist.php local

include 'https://website.eu/config.php';
 
$sql ="SELECT * FROM playlist WHERE playnow > 0 ORDER BY playnow ASC" ;
$result = $conn->query($sql);

Error:
Warning : Undefined variable $conn in C:\Users\user\Desktop\laragon-portable\www\loadplaylist.php on line 7

Fatal error : Uncaught Error: Call to a member function query() on null in C:\Users\user\Desktop\laragon-portable\www\loadplaylist.php:7 Stack trace: #0 {main} thrown in C:\Users\user\Desktop\laragon-portable\www\loadplaylist.php on line 7


How to fix it ?

Any php variable in the server-side code being executed on the web host only exists on the web host. Making a http(s) request to the web host will only receive any output from that code, the same as if you browse to that url on the web host.

Since what you are showing us cannot work, what is the overall top level goal you are trying to accomplish?

1 Like

This is a client project and I don’t want it to see my settings. Is there a way to hide them?

Centralized configuration manager, but it adds complexity

Sponsor our Newsletter | Privacy Policy | Terms of Service