S
S
Sergey Nikolaev2014-12-11 10:40:38
PHP
Sergey Nikolaev, 2014-12-11 10:40:38

Why does the code stop working after connecting the PHP MySQLi class?

The bottom line is, there are two php files.
Contents of the first first.php file:
include_once('class/second.php');
Contents of the second second.php :

include_once ('../lib/MysqliDb.php');
$db = new MysqliDb ('host', 'username', 'password', 'databaseName');
$data = Array ("content" => "text");
$id = $db->insert('Feedback', $data);
if($id)
echo 'Фидбек записан с id '.$id;

The problem is the following: the second file stops working immediately after connecting the MysqliDb
class. In this case, if the connection is in the first file and the call is in the first file, then everything works, but if the connection is in the first file, and the call is in the second, then again it does not work.
What is the problem, how to connect such classes correctly?
Thank you!
Thanks to debugging, I figured it out:
The fact is that when you connect the file first to second, when you connect files from second, you need to write the path, as if you were calling first from the file! Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stadinov Denis, 2014-12-11
@StaDi

new MysqliDb ('', '', '', ''););
doesn't bother you?
and include errors if such cases

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

F
FanatPHP, 2014-12-11
@FanatPHP

Do not underuse this class. It was written by an idiot.
There are TWO fatal errors in this one line at once.
plus there is no normal mysql error handling.
OMG

$this->_mysqli = new mysqli ($this->host, $this->username, $this->password, $this->db, $this->port)
            or die('There was a problem connecting to the database');

And for this you need to tear off your hands, and sew them back to where they actually grow from.
Use this one https://github.com/colshrapnel/safemysql
It certainly doesn't have a poor qwery builder, but in fact you don't need it.

V
Vladimir, 2014-12-11
@rostel

try replacing include_once with require_once

M
Maxim, 2014-12-11
@maxru

All because of the sad emoji.
););

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question