Re: mysqli_connect doesn’t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30.05.2020 at 13:23, Yugroysl wrote:

> I'm having trouble getting PHP7 to connect to a MariaDb database.
> The relevant script is shown below, copied from PHP documentation,
> but it won't connect.
>
> The setup:
>
> System 1: Windows 10, MariaDb 10.4.2, Apache 2.4, PHP 7; SQL client
> HeidiSQL
> System 2: Fedora 32 Workstation, MariaDb 10.4.2, Apache 2.4, PHP 7; SQL
> client Sequeler
>
> The databases on both systems are identical. The users are the same,
> with the same names, privileges and passwords on both. Using HeidiSQL
> I can connect perfectly to the databases on both machines, locally on
> Windows and remotely on Linux from Windows. Sequeler connects perfectly
> on the Linux box locally. Firewalls on both systems are properly
> configured.
>
> Attempts to connect with the following script fail on both systems.
>
>
> <html>
> <head>
> <body>
> <?php
>
> /*
> $host is set to one of these depending on the system:
> 127.0.0.1           locally on Linux
> localhost             locally on Windows
> 192.168.2.55         remotely on Linux from the Windows box
> */
>
> $host = "127.0.0.1";
>
> /*
> these parameters are valid for both machines
> (obviously they're not the real ones!)
> */
> $usr = "me";
> $pw="me123456";
> $db="mydb";
>
> /* this is displayed correctly - shows that the parameters are ok */
> printf("Here: %s, %s, %s, %s<br>",$host,$usr,$pw,$db);
>
> $conn = mysqli_connect($host,$usr,$pw,$db);   /* SCRIPT STOPS HERE */
>
> if ( !$conn ) {
> /* this is never displayed */
>     die("Connect failed!");
>     }
>
> if ( $result=mysqli_query($conn,"SELECT * FROM mytable") ) {
>     $n=mysqli_num_rows($result);
>     }
> mysqli_close($conn);
>
> printf("Found %d records",$n);
> ?>
>
> </body>
> </head>
> </html>
>
> Any ideas, anyone?

Well, do you have full error reporting enabled, and had a look at the
logs (or used display_errors=1)?

And what do you mean with "script stops here" – does it hang, does it crash?

Also, what PHP version are you using exactly?

--
Christoph M. Becker




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux