mysql_connect works; DB::connect doesn't

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lwoods

    #1

    mysql_connect works; DB::connect doesn't

    When I execute the following script I can connect using 'mysqli_connect ' but
    I get a "DB Error: Not Found" when I display the $db->Message() after
    attempting the DB::Connect.

    And, "yes", the "restaurant " database does exist.

    Where should I start looking?

    PHP 5.0.4 / mySQL 4.1.13-nt / IIS / XP Pro

    TIA,

    Larry Woods


    <?php
    require 'DB.php';
    $db=mysqli_conn ect('localhost' ,'root','xxxx', 'restaurant');
    if (! $db ) {
    die("Can't connect: ".mysqli_connec t_error());
    }
    else {
    echo "Connection successful!<br/>";
    mysqli_close($d b);
    }
    $db=DB::connect ('mysql://root:xxxx@local host/restaurant');
    if (DB::isError($d b)) {
    die($db->getMessage() );
    }
    else {
    print "\$db connection was successful!";
    }
    ?>


  • Justin Koivisto

    #2
    Re: mysql_connect works; DB::connect doesn't

    lwoods wrote:
    [color=blue]
    > When I execute the following script I can connect using 'mysqli_connect ' but
    > I get a "DB Error: Not Found" when I display the $db->Message() after
    > attempting the DB::Connect.
    >
    > And, "yes", the "restaurant " database does exist.
    >
    > Where should I start looking?
    >
    > PHP 5.0.4 / mySQL 4.1.13-nt / IIS / XP Pro
    >
    > TIA,
    >
    > Larry Woods
    >
    >
    > <?php
    > require 'DB.php';
    > $db=mysqli_conn ect('localhost' ,'root','xxxx', 'restaurant');
    > if (! $db ) {
    > die("Can't connect: ".mysqli_connec t_error());
    > }
    > else {
    > echo "Connection successful!<br/>";
    > mysqli_close($d b);
    > }
    > $db=DB::connect ('mysql://root:xxxx@local host/restaurant');
    > if (DB::isError($d b)) {
    > die($db->getMessage() );
    > }
    > else {
    > print "\$db connection was successful!";
    > }
    > ?>[/color]

    When using mysqli_* try also mysqli_select_d b and mysqli_query to see if
    there are any odd errors there. Your dsn looks fine, and you check for
    an error the correct way for a PEAR package, but I don't use DB, so the
    only other suggestion I would have is to print_r the $db var if it is an
    error and inspect the other properties. Sometimes the PEAR::Error object
    holds more information than what is returned in getMessage (FME, anyway)

    Comment

    • lwoods

      #3
      Re: mysql_connect works; DB::connect doesn't

      Thanks, Justin,

      I'll play around with it a little more but I think your way is best: Don't
      use DB!

      Larry

      "Justin Koivisto" <justin@koivi.c om> wrote in message
      news:HUJIe.2097 $Ra.12408@news7 .onvoy.net...[color=blue]
      > lwoods wrote:
      >[color=green]
      > > When I execute the following script I can connect using 'mysqli_connect '[/color][/color]
      but[color=blue][color=green]
      > > I get a "DB Error: Not Found" when I display the $db->Message() after
      > > attempting the DB::Connect.
      > >
      > > And, "yes", the "restaurant " database does exist.
      > >
      > > Where should I start looking?
      > >
      > > PHP 5.0.4 / mySQL 4.1.13-nt / IIS / XP Pro
      > >
      > > TIA,
      > >
      > > Larry Woods
      > >
      > >
      > > <?php
      > > require 'DB.php';
      > > $db=mysqli_conn ect('localhost' ,'root','xxxx', 'restaurant');
      > > if (! $db ) {
      > > die("Can't connect: ".mysqli_connec t_error());
      > > }
      > > else {
      > > echo "Connection successful!<br/>";
      > > mysqli_close($d b);
      > > }
      > > $db=DB::connect ('mysql://root:xxxx@local host/restaurant');
      > > if (DB::isError($d b)) {
      > > die($db->getMessage() );
      > > }
      > > else {
      > > print "\$db connection was successful!";
      > > }
      > > ?>[/color]
      >
      > When using mysqli_* try also mysqli_select_d b and mysqli_query to see if
      > there are any odd errors there. Your dsn looks fine, and you check for
      > an error the correct way for a PEAR package, but I don't use DB, so the
      > only other suggestion I would have is to print_r the $db var if it is an
      > error and inspect the other properties. Sometimes the PEAR::Error object
      > holds more information than what is returned in getMessage (FME, anyway)[/color]



      Comment

      • Justin Koivisto

        #4
        Re: mysql_connect works; DB::connect doesn't

        lwoods wrote:
        [color=blue]
        > Thanks, Justin,
        >
        > I'll play around with it a little more but I think your way is best: Don't
        > use DB![/color]

        I've actually been using MDB, but when I finally get a production server
        with php5, I will have to check out sqllite to see if what I've been
        doing with databases can all be accomplished with that. If that is the
        case, then I'll get rid of abstraction all together since it will be
        portable enough for my case.

        --
        Justin Koivisto, ZCE - justin@koivi.co m

        Comment

        • lwoods

          #5
          Re: mysql_connect works; DB::connect doesn't

          I'm going the sqlite direction myself because most of my databases are not
          that complex. Also, the price is right...and it's installed everywhere php5
          is installed.

          Larry

          "Justin Koivisto" <justin@koivi.c om> wrote in message
          news:3gKIe.2099 $Ra.12603@news7 .onvoy.net...[color=blue]
          > lwoods wrote:
          >[color=green]
          > > Thanks, Justin,
          > >
          > > I'll play around with it a little more but I think your way is best:[/color][/color]
          Don't[color=blue][color=green]
          > > use DB![/color]
          >
          > I've actually been using MDB, but when I finally get a production server
          > with php5, I will have to check out sqllite to see if what I've been
          > doing with databases can all be accomplished with that. If that is the
          > case, then I'll get rid of abstraction all together since it will be
          > portable enough for my case.
          >
          > --
          > Justin Koivisto, ZCE - justin@koivi.co m
          > http://koivi.com[/color]



          Comment

          • Marcin Dobrucki

            #6
            Re: mysql_connect works; DB::connect doesn't


            Two things:

            1) your DSN for the DB should be:

            'mysqli://root:xxxx@local host/restaurant'

            (see details on:
            http://pear.php.net/manual/en/packag....intro-dsn.php)

            2) You probably want to do this instead:

            $db =& DB::connect(... .);

            There is little point copying the object.

            And don't get discouraged. DB works very well indeed, and will allow
            you to switch your DB at any point later (unlike using the mysqli...
            methods).

            /Marcin

            lwoods wrote:[color=blue]
            > When I execute the following script I can connect using 'mysqli_connect ' but
            > I get a "DB Error: Not Found" when I display the $db->Message() after
            > attempting the DB::Connect.
            >
            > And, "yes", the "restaurant " database does exist.
            >
            > Where should I start looking?
            >
            > PHP 5.0.4 / mySQL 4.1.13-nt / IIS / XP Pro
            >
            > TIA,
            >
            > Larry Woods
            >
            >
            > <?php
            > require 'DB.php';
            > $db=mysqli_conn ect('localhost' ,'root','xxxx', 'restaurant');
            > if (! $db ) {
            > die("Can't connect: ".mysqli_connec t_error());
            > }
            > else {
            > echo "Connection successful!<br/>";
            > mysqli_close($d b);
            > }
            > $db=DB::connect ('mysql://root:xxxx@local host/restaurant');
            > if (DB::isError($d b)) {
            > die($db->getMessage() );
            > }
            > else {
            > print "\$db connection was successful!";
            > }
            > ?>
            >
            >[/color]

            Comment

            Working...