I cannot find the solution, spending hours of troubleshooting, though. Frustration growns steadily.
The problem: I try, after transferring a web page to a new provider that requires the oop approach for mysql interfaces, to reset all the sql command lines. This works fine. But there is one part that I cannot get working. The called php-file movie.php looks like:
<?php
include 'scripts/init.php';
...
$cameraString = AssignPerson( $movieID, 'camera' );
?>
The important bits from init.php are:
<?php
session_start();
include 'scripts/connect2SQL.php';
include 'scripts/logInOut.php';
include 'scripts/classes_functions.php';
?>
The connect2SQL.php reads
<?php
$connection2MySQL = mysqli_connect( "localhost" , "***" , "***", "***");
mysqli_query( $connection2MySQL , "SET CHARACTER SET 'utf8'" );
mysqli_query($connection2MySQL , "SET SESSION collation_connection ='utf8_unicode_ci'" );
?>
So the variable $connection2MySQL represents the oop connection to the database.
The function AssignPerson( $movieID, 'camera' ); in the movie.php is defined in the classes-file classes_functions.php. Here, the essential snippets are
function AssignPerson( $objectID, $type = 'actor' ) {
$memoryString = '';
// THAT FOLLOWING LINE IS NOT WORKING :::
$persons = $connection2MySQL->query( "SELECT * FROM actors2movies" );
if ( mysqli_num_rows( $persons ) ) {
while ($person = mysqli_fetch_assoc( $persons )) {
$personID = $person['personeID'];
$memoryString .= $person['personName'];
}
}
return $memoryString;
}
The error message that comes up in the browser looks like:
Fatal error: Uncaught Error: Call to a member function query() on null in /var/www/web26777278/html/filmstadt-quedlinburg/scripts/classes_functions.php:173 Stack trace: #0 /var/www/web26777278/html/filmstadt-quedlinburg/movie.php(354): AssignPerson('800', 'director') #1 {main} thrown in /var/www/web26777278/html/filmstadt-quedlinburg/scripts/classes_functions.php on line 173
The issue here is, that when I delete the lines of the query (and the following ones), the program works. So the error must be in the line i indicated above. On the other hand, if I copy that line directly into the movie.php, the line works! So it must have to do something with the encapsuling thing of php-files into the others.
I checked if I need to repeat the including line of the SQL connection in the classes.php. I checked also, whether there are forgotten brackets, spelling mistakes in the database tables and that kind of things. Can't help myself.
Do you have any idea where I could have another look for the problem?
Greetings and thank you Frank