Unable to connect to mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyberking
    New Member
    • Jan 2007
    • 84

    Unable to connect to mysql database

    Hi.
    I have just started learning PHP along with MySQL.

    I am trying to connect to the MySQL DB server but unable to. I have been tryin. Please help. Its urgent cos I shall soon have to work on PHP .

    My testing program is as follows :

    Code:
     <?php 
     
    $si = function_exists('mysqli_connect');
    if($si == 1)
    {
    echo 'MySQL is installed <br />';
    }
    else
    {
    echo 'Not able to connect';
    }
    ?>
    Please help. I am unable to connect to the MySQL server
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    [PHP]function_exists ('mysqli_connec t');
    [/PHP]
    mysqli_connect is not the correct function
    mysql_connect is the function

    remove "i" from the function name

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      When you post next time please read the posting guidelines.
      Please give a proper title to your thread and wrap the coding using tags. because then from this page itself we can read the codings without going for a IDE.

      Comment

      • cyberking
        New Member
        • Jan 2007
        • 84

        #4
        Yes. Ok I ll Follow the rules from the next time.

        But For now, I still am not able to connect. Please see the following statement.

        $dbcnx = mysql_connect(" localhost","roo t","my_pass" );

        This is in the browser gives me a Fatal Error.

        Wats the prob. Please help.

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Originally posted by cyberking
          Yes. Ok I ll Follow the rules from the next time.

          But For now, I still am not able to connect. Please see the following statement.

          $dbcnx = mysql_connect(" localhost","roo t","my_pass" );

          This is in the browser gives me a Fatal Error.

          Wats the prob. Please help.
          [PHP]$dbcnx = mysql_connect(" localhost","roo t","my_pass" );[/PHP]
          this line is not in your original post.
          I just made the correction of your script.here its checking weather [PHP]mysql_connect[/PHP] is defined or not.

          what do you really wanted. post the complete script here.

          Comment

          • cyberking
            New Member
            • Jan 2007
            • 84

            #6
            Originally posted by ajaxrand
            [PHP]$dbcnx = mysql_connect(" localhost","roo t","my_pass" );[/PHP]
            this line is not in your original post.
            I just made the correction of your script.here its checking weather [PHP]mysql_connect[/PHP] is defined or not.

            what do you really wanted. post the complete script here.
            Hi.
            Thanks for takin time to help me.

            This is my first program where I am tryin to connect to MySQL server. The complete code is as follows:


            <?php

            $dbcnx = mysql_connect(" localhost","roo t","my_pass" );
            if ($dbcnx)
            {
            echo 'Success';
            }
            else
            {
            echo ' Unable' ;
            }
            But I still get the same error.
            Fatal Error: Call to undefined function mysql_connect

            Thanks in advance

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Did you install mysql in your machine. this script is working fine with correct username and password to mysql server witch runs in the same machine.

              [PHP]<?php
              $dbcnx = mysql_connect(" localhost","roo t","dba");
              if ($dbcnx)
              {
              echo 'Success';
              }
              else
              {
              echo ' Unable' ;
              }
              ?>[/PHP]

              use [PHP] tags arround your php lines ;)

              Comment

              • cyberking
                New Member
                • Jan 2007
                • 84

                #8
                Is that So??

                Yes I have MySQL, Apache and PHP all installed on my system. But then, why is it not working for me?

                Thanks again for tryin to help me

                Comment

                • ak1dnar
                  Recognized Expert Top Contributor
                  • Jan 2007
                  • 1584

                  #9
                  Originally posted by cyberking
                  Is that So??

                  Yes I have MySQL, Apache and PHP all installed on my system. But then, why is it not working for me?

                  Thanks again for tryin to help me
                  Do you have phpMyAdmin installed in your system. and what is the O/S.

                  Comment

                  • cyberking
                    New Member
                    • Jan 2007
                    • 84

                    #10
                    I have XP and I don have PhpMyadmin.

                    Comment

                    • ak1dnar
                      Recognized Expert Top Contributor
                      • Jan 2007
                      • 1584

                      #11
                      Originally posted by cyberking
                      I have XP and I don have PhpMyadmin.
                      download appserv and install it.
                      remove all your PHP,MySQL,Apach e from the system.

                      give a fresh copy. Appserv is consist of PHP,APACHE,MySQ L,phpMyAdmin in a single pack.

                      once you done try the coding again.

                      Comment

                      • cyberking
                        New Member
                        • Jan 2007
                        • 84

                        #12
                        But do i need phpmyadmin? Is it not possible without it?

                        Sorry. but the reason why I am asking is because I just installed all the three, mysql, PHP5 and apache. Is there anything that I have to do in the php.ini file. i even added the php_mysql.dll extension in the php.ini

                        Comment

                        • ak1dnar
                          Recognized Expert Top Contributor
                          • Jan 2007
                          • 1584

                          #13
                          Originally posted by cyberking
                          But do i need phpmyadmin? Is it not possible without it?

                          Sorry. but the reason why I am asking is because I just installed all the three, mysql, PHP5 and apache. Is there anything that I have to do in the php.ini file. i even added the php_mysql.dll extension in the php.ini
                          You have to put libmysql.dll to Windows dir.

                          Comment

                          • cyberking
                            New Member
                            • Jan 2007
                            • 84

                            #14
                            Originally posted by ajaxrand
                            You have to put libmysql.dll to Windows dir.
                            I tried doin it. But still without any results, I still get the same error.. please help.

                            Comment

                            • ak1dnar
                              Recognized Expert Top Contributor
                              • Jan 2007
                              • 1584

                              #15
                              Problem is with your system not in the coding. so it is up to you. here we can help if there is a error in the coding. again we can give the suggestions for up your system.thats it.

                              Comment

                              Working...