NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Connecting to MySQL for first time

 
Post new topic   Reply to topic    NetBeans Forums -> PHP Users
View previous topic :: View next topic  
Author Message
liamfitz



Joined: 22 Nov 2016
Posts: 10

PostPosted: Thu Nov 24, 2016 3:54 pm    Post subject: Connecting to MySQL for first time Reply with quote

I'm having trouble connecting to 'MySQL' ( using MAMP ) ... Here's my PHP file ..
Code:
<html>
    <head>
        <meta charset="UTF-8">
        <title>Connect To Database</title>
    </head>
    <body>
    <?php
    # Connect on 'localhost' for user 'liam'
        # with password 'easysteps' to database 'site_db'.
        $host = 'localhost';
        $user = 'liam';
        $password = 'easysteps';
        $database = 'site_db';
        $port = '3306';
        $socket = '/Applications/MAMP/tmp/mysql/mysql.sock';
        $dbc = mysqli_connect($host, $user, $password, $database, $port, $socket)
                OR die
                (mysqli_connect_error());
        # set encoding to match PHP script encoding.
        mysqli_set_charset($dbc, 'utf8');
        # Incorporate the MySQL connection script.
        require ('/Applications/MAMP/htdocs/Database_Connection/connect_db.php');
        if(mysqli_ping($dbc))
        {
            echo 'MySQL Server '.mysqli_get_server_info($dbc).' on '.mysqli_get_host_info($dbc);
        }
        ?>
    </body>
</html>

I'm getting error message ... "Thu Nov 24 15:22:51 2016] ::1:49462 [404]: /Database_Connection/connect_db.php - No such file or directory".
Any Suggestions would be gratefully received. I'm quite new to PHP & MySQL. Thank you.
Back to top
paolosca



Joined: 09 Sep 2010
Posts: 513

PostPosted: Mon Nov 28, 2016 1:26 am    Post subject: Connecting to MySQL for first time Reply with quote

Hi,

Your script requires /Applications/MAMP/htdocs/Database_Connection/connect_db.php, does the file exists in the specified directory?


Also, since you are using an external library, make sure it's configured with the right paths.


Regards,


Paolo


On Thu, Nov 24, 2016 at 11:54 PM, liamfitz <address-removed ([email]address-removed[/email])> wrote:
Quote:
I'm having trouble connecting to 'MySQL' ( using MAMP ) ... Here's my PHP file ..

Code:
<html>
    <head>
        <meta charset="UTF-8">
        <title>Connect To Database</title>
    </head>
    <body>
    <?php
    # Connect on 'localhost' for user 'liam'
        # with password 'easysteps' to database 'site_db'.
        $host = 'localhost';
        $user = 'liam';
        $password = 'easysteps';
        $database = 'site_db';
        $port = '3306';
        $socket = '/Applications/MAMP/tmp/mysql/mysql.sock';
        $dbc = mysqli_connect($host, $user, $password, $database, $port, $socket)
                OR die
                (mysqli_connect_error());
        # set encoding to match PHP script encoding.
        mysqli_set_charset($dbc, 'utf8');
        # Incorporate the MySQL connection script.
        require ('/Applications/MAMP/htdocs/Database_Connection/connect_db.php');
        if(mysqli_ping($dbc))
        {
            echo 'MySQL Server '.mysqli_get_server_info($dbc).' on '.mysqli_get_host_info($dbc);
        }
        ?>
    </body>
</html>


I'm getting error message ...  "Thu Nov 24 15:22:51 2016] ::1:49462 [404]: /Database_Connection/connect_db.php - No such file or directory".
Any Suggestions would be gratefully received. I'm quite new to PHP & MySQL. Thank you.




Back to top
liamfitz



Joined: 22 Nov 2016
Posts: 10

PostPosted: Mon Nov 28, 2016 9:54 pm    Post subject: Reply with quote

No - there are no files in 'htdocs' folder - so the path would end at ...

/Applications/MAMP/htdocs

rather than ....

/Applications/MAMP/htdocs/Database_Connection/connect_db.php
Back to top
paolosca



Joined: 09 Sep 2010
Posts: 513

PostPosted: Tue Nov 29, 2016 9:52 am    Post subject: Connecting to MySQL for first time Reply with quote

The line

require ('/Applications/MAMP/htdocs/Database_Connection/connect_db.php');



tries to include connect_db.php which is supposed to be in /Applications/MAMP/htdocs/Database_Connection/, you should either copy the script in that folder or change the "require" path to the correct folder.


Regards,


Paolo


On Tue, Nov 29, 2016 at 5:54 AM, liamfitz <address-removed ([email]address-removed[/email])> wrote:
Quote:
No - there are no files in 'htdocs' folder - so the path would end at ...

/Applications/MAMP/htdocs

rather than ....

/Applications/MAMP/htdocs/Database_Connection/connect_db.php




Back to top
liamfitz



Joined: 22 Nov 2016
Posts: 10

PostPosted: Tue Nov 29, 2016 5:20 pm    Post subject: Reply with quote

Thank you - that makes perfect sense, but I don't have any 'script' in folder htdocs, ( or any other destination folder/file ) in fact, the folder htdocs is completely empty. I suspect the problem is there should be a file, which would -
# Incorporate the MySQL connection script.
What is this 'connection script', or where can I find it ?
You've been most helpful, and your patience and help is much appreciated.
Back to top
liamfitz



Joined: 22 Nov 2016
Posts: 10

PostPosted: Tue Nov 29, 2016 8:40 pm    Post subject: Reply with quote

I think I'm nearly there .... this script called index1.php
Code:

<html>
    <head>
        <meta charset="UTF-8">
        <title>Getting Started With PHP</title>
    </head>
    <body>
        <?php
        # Write the traditional greeting
        $phrase = 'The truth is rarely pure';
        $author = 'Oscar Wilde';
       
        echo "<h2>$phrase</h2>";
        echo '<h1>Hello World !</h1>';
        # Connect on 'localhost' for user 'liam'
       # with password '******' to database 'site_db'.
       $user = 'root';
      $password = 'root';
      $db = 'inventory';
      $host = 'localhost';
      $port = 8889;

      $link = mysqli_init();
      $dbc = mysqli_real_connect($link, $host, $user, $password, $db, $port);
      
      # Incorporate the MySQL connection script.
        require ('/Applications/MAMP/htdocs/connect_db.php');
        # Display MySQL version and host.
        if(mysqli_ping($dbc))
        {
            echo 'MySQL Server '.mysqli_get_server_info($dbc).' on '.mysqli_get_host_info($dbc);
        }       
        ?>
    </body>
</html>


produces the following valid output, and errors, on web-page ...

The truth is rarely pure

Hello World !

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Applications/MAMP/htdocs/connect_db.php on line 17

Warning: mysqli_ping() expects parameter 1 to be mysqli, boolean given in /Library/WebServer/Documents/index1.php on line 39



The file connect_db.php 'required', is as follows ...
Code:
<html>
    <head>
        <meta charset="UTF-8">
        <title>Getting Started With PHP</title>
    </head>
    <body>
    <?php
    # Connect on 'localhost' for user 'liam'
    # with password '******' to database 'inventory'.
    $user = 'root';
   $password = 'root';
   $db = 'inventory';
   $host = 'localhost';
   $port = 8889;

   $link = mysqli_init();
   $dbc = mysqli_real_connect($link, $host, $user, $password, $db, $port);   
    ?>
    </body>
</html>


Any help would be greatly appreciated. Thanks.
Back to top
paolosca



Joined: 09 Sep 2010
Posts: 513

PostPosted: Mon Dec 05, 2016 3:17 am    Post subject: Connecting to MySQL for first time Reply with quote

Hi,

The error is likely due to the wrong password, I don't normally use MySQL it's possible the default password is "" (no password).


Try changing the following line:


$password = 'root';



in:


$password = '';



If that fails and you don't remember your MySQL root user password, I suggest you try to reset it. You should be able to google for the instructions.


Have a nice day,


Paolo


On Wed, Nov 30, 2016 at 4:40 AM, liamfitz <address-removed ([email]address-removed[/email])> wrote:
Quote:
I think I'm nearly there .... this script called index1.php

Code:

<html>
    <head>
        <meta charset="UTF-8">
        <title>Getting Started With PHP</title>
    </head>
    <body>
        <?php
        # Write the traditional greeting
        $phrase = 'The truth is rarely pure';
        $author = 'Oscar Wilde';

        echo "<h2>$phrase</h2>";
        echo '<h1>Hello World !</h1>';
        # Connect on 'localhost' for user 'liam'
        # with password '******' to database 'site_db'.
        $user = 'root';
                $password = 'root';
                $db = 'inventory';
                $host = 'localhost';
                $port = 8889;

                $link = mysqli_init();
                $dbc = mysqli_real_connect($link, $host, $user, $password, $db, $port);

                # Incorporate the MySQL connection script.
        require ('/Applications/MAMP/htdocs/connect_db.php');
        # Display MySQL version and host.
        if(mysqli_ping($dbc))
        {
            echo 'MySQL Server '.mysqli_get_server_info($dbc).' on '.mysqli_get_host_info($dbc);
        }
        ?>
    </body>
</html>



produces the following valid output, and errors, on web-page  ...

The truth is rarely pure

Hello World !

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Applications/MAMP/htdocs/connect_db.php on line 17

Warning: mysqli_ping() expects parameter 1 to be mysqli, boolean given in /Library/WebServer/Documents/index1.php on line 39


The file connect_db.php 'required', is as follows ...

Code:
<html>
    <head>
        <meta charset="UTF-8">
        <title>Getting Started With PHP</title>
    </head>
    <body>
    <?php
    # Connect on 'localhost' for user 'liam'
    # with password '******' to database 'inventory'.
    $user = 'root';
        $password = 'root';
        $db = 'inventory';
        $host = 'localhost';
        $port = 8889;

        $link = mysqli_init();
        $dbc = mysqli_real_connect($link, $host, $user, $password, $db, $port);
    ?>
    </body>
</html>



Any help would be greatly appreciated. Thanks.




Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> PHP Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo