1

Topic: Fatal error: in ***/Connect.php on line 11

Hello, transferred basis on other machine (mariadb 10.* Debian 9), after transfer why that ceased to work one of scripts, the error sounds so: Fatal error: in ***/Connect.php on line 11 (the full address is hidden).
The script looks so:

<? php
$xml = simplexml_load_file ("$root/db_conf.xml");
$host = $xml-> host [0];
$dbname = $xml-> dbname [0];
$user = $xml-> user [0];
$password = $xml-> password [0];
$table = $xml-> table [0];
$db = new \PDO ("mysql: host = $ host; dbname = $ dbname", $user, $password);
$db-> setAttribute (\PDO:: ATTR_ERRMODE, \PDO:: ERRMODE_EXCEPTION);
$db-> setAttribute (\PDO:: ATTR_DEFAULT_FETCH_MODE, \PDO:: FETCH_NUM);
$db-> exec ("SET NAMES ' utf8 '");
$db-> exec ("SET CHARACTER SET ' utf8 '");
$db-> exec ("SET SESSION collation_connection = ' utf8_general_ci '");

11th line: $db = new \PDO ("mysql: host = $ host; dbname = $ dbname", $user, $password);
Prompt please in what there can be an error and how it it is possible corrects?
The moderator: the Subject is transferred from a forum "MySQL".

2

Re: Fatal error: in ***/Connect.php on line 11

try {
$db = new \PDO ("mysql: host = $ host; dbname = $ dbname", $user, $password);
}
catch (\Exception $e) {
var_dump ($e-> getMessage ());
}

3

Re: Fatal error: in ***/Connect.php on line 11

opiums wrote:

Hello, transferred basis on other machine (mariadb 10.* Debian 9), after transfer why that one of scripts

Too  the error report ceased to work. It is more than normally particulars.
Well basis it is not enough , it is necessary still there to the mysql-user to give access to this basis and a connection config in scripts to correct.
The superfluous will not check up availability of the server from a DBMS on a network. At least telnet'.

4

Re: Fatal error: in ***/Connect.php on line 11

ScareCrow;

string (52) "SQLSTATE [HY000] [1049] Unknown database ' craftedweb '"
Notice: Undefined variable: db in */Connect.php on line 18
Fatal error: Call to a member function setAttribute () on null in */Connect.php on line 18

, craftedweb in the list there is also an access too is to it...
18: $db-> setAttribute (\PDO:: ATTR_ERRMODE, \PDO:: ERRMODE_EXCEPTION);

5

Re: Fatal error: in ***/Connect.php on line 11

vkle;
Availability is, connection from other sites to this machine, basis and even the table transit successfully and without errors, this script does not work only.
P.S.

mysql - version
mysql Ver 15.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

6

Re: Fatal error: in ***/Connect.php on line 11

It is possible to assume that the basis is incorrectly specified or the server is specified incorrectly or if the domain name is filled out, it  is wrong. Otherwise whence to undertake "Unknown database ' craftedweb '"

7

Re: Fatal error: in ***/Connect.php on line 11

vkle;
No, with connection of problems is not present, used here such script for check now:

<? php
$dbhost = "192.168.1.7";//Host name for connection to a DB
$dbusername = "name";//the User of a database
$dbpass = "pass";//the Password to a database
$dbname = "craftedweb";//a database Name
$dbconnect = mysql_connect ($dbhost, $dbusername, $dbpass);
if (! $dbconnect) {echo ("it is not possible to be connected to a database server!");}
if (@mysql_select_db ($dbname)) {echo "Connection to a database $dbname is installed!";}
else die ("it is not possible to be connected to a database $dbname!");
?>

Also received:
Connection to a database craftedweb is installed!
And yes, I use connection to the local machine.

8

Re: Fatal error: in ***/Connect.php on line 11

And requests to basis from this connection regularly work?

9

Re: Fatal error: in ***/Connect.php on line 11

vkle;
Yes, at least an output through mysqli it is exact:

$dbconnect = new mysqli ($dbhost, $dbusername, $dbpass, $dbname);

10

Re: Fatal error: in ***/Connect.php on line 11

The shaitan, however. At first sight. What is known about version PHP, about the version of an old DBMS where a whisker worked? Probably, any incompatibility  the driver pdo-mysql with leaking  a DBMS.

11

Re: Fatal error: in ***/Connect.php on line 11

vkle;
The previous machine:

php-ver
PHP 5.6.31 (cli) (built: Jul 5 2017 10:25:39 PM)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
mysql - version
mysql Ver 14.14 Distrib 5.7.17, for Win64 (x86_64)

OS: win 7, IIS 7.5

12

Re: Fatal error: in ***/Connect.php on line 11

Did not understand, PHP scripts too moved?

13

Re: Fatal error: in ***/Connect.php on line 11

vkle;
No, php-scripts did not move, they remained on a place.
On 1 to the machine the script is launched, it takes the information from DBMS MySQL 2 (the local machine).
It is probably necessary as that correctly to register connection then also all turns out.

14

Re: Fatal error: in ***/Connect.php on line 11

Well would be PHP and a DBMS not to one machine - then it is possible to specify connections as localhost (it and works more bright). At you the machine different, it does not turn out so.
And in general, strange enough situation. Such impression that pdo_mysql not in a state to agree from a DBMS - nevertheless, MySQL and MariaDB not absolutely alone and the same. Though, mysqli works... Did not look in phpinfo (), the driver for pdo_mysql and mysqli it is used same or different?

15

Re: Fatal error: in ***/Connect.php on line 11

vkle;
Identical, mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ .
I assume that I use old pdo connection to mysql which is not supported any more mariadb, and it is necessary as that to translate all with pdo on mysqli, but I not so am strong in php, therefore I do not know as will change more correctly connection with pdo on mysqli.

16

Re: Fatal error: in ***/Connect.php on line 11

opiums wrote:

I assume that I use old pdo connection to mysql which is not supported any more mariadb

a DBMS somehow on a drum that there on the client is used. About existence PDO and other PHP extensions it not in course.

opiums wrote:

also it is necessary as that to translate all with pdo on mysqli, but I not so am strong in php, therefore I do not know as will change more correctly connection with pdo on mysqli.

it is different PHP extensions. On simple speaking, all PDO-shnoe should be rewritten on mysqli-shnoe. If scripts more than several pieces, which can be corrected and debugged in hour or so then much easier to replace a DBMS on MySQL, for that matter. Though, it is possible to try and PHP to update to the last version (I do not think that helps, but nevertheless). Still is a few adjustments of the driver http://php.net/manual/ru/ref.pdo-mysql.php But at first sight, there anything such.
All right, as experiment. In a variant with PDO one basis ` craftedweb `, or standard, say, ` mysql ` or ` test ` too turns out "Unknown" only, the type, does not exist?

17

Re: Fatal error: in ***/Connect.php on line 11

vkle;
To bases mysql and performance_schema it is connected, the data receives, to all remaining bases does not want in any, the same error

18

Re: Fatal error: in ***/Connect.php on line 11

vkle;
Result of connection on a screen

19

Re: Fatal error: in ***/Connect.php on line 11

On idea, the basis ` information_schema ` too should be accessible (in MySQL there is such system basis, but for MariaDB will not tell). Then, basically, it is possible to assume that PDO works with this server.
In my opinion, there is a sense in details to work two versions.
1. The rights of the mysql-user with which connection is fulfilled.
And, if with the rights everything is all right,
2. Actually connection happens not to that server (host) which is set in adjustments. To define it it is easily possible on contents (bases, the tables given) and on system variables (the same hostname, for example).

20

Re: Fatal error: in ***/Connect.php on line 11

vkle;
and if and with the rights everything is all right and connection is registered truly?

21

Re: Fatal error: in ***/Connect.php on line 11

Meant not that actual connection is registered in a script, and. Probably, given adjustment DSN was not applied for any reason.
In config PHP, by the way, for PDO it is possible to set this parameter php.net/manual/ru/pdo.configuration.php For what so it is made - not quite clearly. As will behave PHP or PDO at unsuccessful connection on set in script DSN in the presence of registered in a config - I not undertake to judge. Whether will take alternative from a config or not - about it in a manual it is not written.
Therefore, when appreciable errors and misprints are not present (including such mistakes as "c" Latin and "with" Russian), is sense to continue problem search , at more thin level. In an opposite case it is necessary to establish only the fact "it does not work". However, the reason of it "does not work" is not clear, is not found.
Hypothetically, the route can be turned anywhere network routing, for example, including for separate port. But it not your case for mysqli works.

22

Re: Fatal error: in ***/Connect.php on line 11

I could launch a script by the local machine, there, where transferred basis. All was launched both under , and under that user under whom it was connected from other machine, the reasons why so happens and is not clear

23

Re: Fatal error: in ***/Connect.php on line 11

The user has rights with  and there are no rights with remote IP

24

Re: Fatal error: in ***/Connect.php on line 11

opiums wrote:

all Was launched both under , and under that user under whom it was connected from other machine, the reasons why so happens and is not clear

Look at users of a DBMS and their right. For example, ' user ' ' localhost ', ' user ' ' % ' and as ' user ' ' server.local ' and ' user ' ' 192.168.10.20 ' are different users (even if server.local  in 192.168.10.20 and on the contrary). Not always it is possible for unwinding to define precisely under what it is is specific user name there was a connection (well, except ).

25

Re: Fatal error: in ***/Connect.php on line 11

vkle;
At the user all rights are, ' user ' ' % ', through  connection easy transits, as well as through remaining programs - navicat, heidisql as I added forcedly bases, it as did not give effect