Is my code for seeing a database wrong? Please help - getting very desperate!

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

    Is my code for seeing a database wrong? Please help - getting very desperate!

    Please help - getting very desperate! Sun, 12 October 2003 05:39

    I have PHPDEV 4.2.3 from Firepages.com.a u as the upgrade to 4.3.0 did
    not work. I also had an abortive download from PHP.NET as I could not
    configure Apache myself.

    The REAL problem is that PHPmyAdmin works and sees my test database
    Wines....
    But my PHP program does not!

    The code I have used is:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <TITLE> Getting PHP & MY SQL to work </TITLE>
    <head>Wines PHP Tester<BR></head>
    <body>
    <?php
    echo "This is PHP here....<BR>\n" ;


    $link_id = @msql_pconnect( "localhost" );
    if (!$link_id) {
    echo ("Failed to connect to MySQL!");
    exit;
    }
    else;
    {
    echo "Connected OK!";
    }

    if (!mysql_select_ db("Wines")) {
    echo ("Failed to select database cms!");
    exit;

    }
    echo ("Connected to Database");
    $resultset = mysql_query("SE LECT * FROM wine");
    while ($row = mysql_fetch_row ($resultset)) {
    echo "Date $row[0]: $row[1]\n";
    }
    echo ("end");
    ?>
    </html>
    </BODY>
    </HTML>

    And I have also tried:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Getting PHP & MY SQL to work </TITLE>
    </HEAD>

    <BODY>
    <html>
    <head>Wines PHP Tester<BR></head>
    <body>


    <?php
    echo "This is PHP here....<BR>\n" ;
    $connection = mysql_connect(" localhost");

    $db = mysql_select_db ("Wines",$conne ction);
    $query = "SELECT * FROM Wine";
    echo "Select..." ;
    $result = mysql_query($qu ery,$connection );
    echo "result..." ;

    ?>
    </body>
    </html>
    </BODY>
    </HTML>
    But I get no results. It works fine in PHPmyAdmin though.

    I did have a different Mysql on my XPHome box which I have
    subsequently deleted as it could not connect to the server once PHP
    was installed.

    I am falling further behind in my degree as I can even get the db up
    and running so I cant even get coding!

    Please please help.
  • warstar

    #2
    Re: Is my code for seeing a database wrong? Please help - getting very desperate!

    try this

    <?php
    class base
    {
    #### SQL ####
    //In this part of the Base class are located all sql related
    functions
    var $connected = false;

    function sql_connect() //In this function u make a sql connection
    {
    ############# FILL THIS IN: #############
    $mysqlhost = 'localhost'; // Database
    provider URL
    $mysqluser = 'tobegood_test' ; // Database
    gebruiker
    $mysqlpassword = 'test'; // Database wachtwoord
    $mysqldb = 'tobegood_test1 '; // Database
    naam
    ############# That was all thnx ###########
    if(!$this->connected)
    {
    $conn =
    mysql_connect($ mysqlhost,$mysq luser,$mysqlpas sword) or die("Could not
    connect to database!");
    $select = mysql_select_db ($mysqldb,$conn ) or
    die("Could not select the database!");
    $connected = true;
    }
    }

    function sql_query($quer y) //With this function u do a sql query
    {
    if(!$this->connected)
    {
    $this->sql_connect( );
    }
    $result = mysql_query($qu ery) or die("MySQL error :
    ".mysql_error() );
    return ($result);
    }
    #### End SQL ####
    }

    class test extends base
    {
    function test()
    {
    $sql = $this->sql_query("SEL ECT * FROM wine");
    $count = 0;
    while($info = mysql_fetch_arr ay($sql))
    {
    echo $info[$count];
    $count++;
    }
    }
    }

    $test = new test();

    ?>

    Haven't tested it because my php server is down but it should work

    good luck

    On 12 Oct 2003 03:15:28 -0700, just_out_for_fu n@hotmail.com (James)
    wrote:
    [color=blue]
    >Please help - getting very desperate! Sun, 12 October 2003 05:39
    >
    >I have PHPDEV 4.2.3 from Firepages.com.a u as the upgrade to 4.3.0 did
    >not work. I also had an abortive download from PHP.NET as I could not
    >configure Apache myself.
    >
    >The REAL problem is that PHPmyAdmin works and sees my test database
    >Wines....
    >But my PHP program does not!
    >
    >The code I have used is:
    >
    ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    ><HTML>
    ><TITLE> Getting PHP & MY SQL to work </TITLE>
    ><head>Wines PHP Tester<BR></head>
    ><body>
    ><?php
    >echo "This is PHP here....<BR>\n" ;
    >
    >
    >$link_id = @msql_pconnect( "localhost" );
    >if (!$link_id) {
    >echo ("Failed to connect to MySQL!");
    >exit;
    >}
    >else;
    >{
    >echo "Connected OK!";
    >}
    >
    >if (!mysql_select_ db("Wines")) {
    >echo ("Failed to select database cms!");
    >exit;
    >
    >}
    >echo ("Connected to Database");
    >$resultset = mysql_query("SE LECT * FROM wine");
    >while ($row = mysql_fetch_row ($resultset)) {
    >echo "Date $row[0]: $row[1]\n";
    >}
    >echo ("end");
    >?>
    ></html>
    ></BODY>
    ></HTML>
    >
    >And I have also tried:
    >
    ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    ><HTML>
    ><HEAD>
    ><TITLE> Getting PHP & MY SQL to work </TITLE>
    ></HEAD>
    >
    ><BODY>
    ><html>
    ><head>Wines PHP Tester<BR></head>
    ><body>
    >
    >
    ><?php
    >echo "This is PHP here....<BR>\n" ;
    >$connection = mysql_connect(" localhost");
    >
    >$db = mysql_select_db ("Wines",$conne ction);
    >$query = "SELECT * FROM Wine";
    >echo "Select..." ;
    >$result = mysql_query($qu ery,$connection );
    >echo "result..." ;
    >
    >?>
    ></body>
    ></html>
    ></BODY>
    ></HTML>
    >But I get no results. It works fine in PHPmyAdmin though.
    >
    >I did have a different Mysql on my XPHome box which I have
    >subsequently deleted as it could not connect to the server once PHP
    >was installed.
    >
    >I am falling further behind in my degree as I can even get the db up
    >and running so I cant even get coding!
    >
    >Please please help.[/color]

    Comment

    • sam

      #3
      Re: Is my code for seeing a database wrong? Please help - getting very desperate!


      "James" <just_out_for_f un@hotmail.com> wrote in message
      news:4e2d029c.0 310120215.3fd7c d5a@posting.goo gle.com...[color=blue]
      > Please help - getting very desperate! Sun, 12 October 2003 05:39
      >
      > I have PHPDEV 4.2.3 from Firepages.com.a u as the upgrade to 4.3.0 did
      > not work. I also had an abortive download from PHP.NET as I could not
      > configure Apache myself.
      >
      > The REAL problem is that PHPmyAdmin works and sees my test database
      > Wines....
      > But my PHP program does not!
      >
      > The code I have used is:
      >
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      > <HTML>
      > <TITLE> Getting PHP & MY SQL to work </TITLE>
      > <head>Wines PHP Tester<BR></head>
      > <body>
      > <?php
      > echo "This is PHP here....<BR>\n" ;
      >
      >
      > $link_id = @msql_pconnect( "localhost" );[/color]

      mysql and not msql !

      $link_id = @mysql_pconnect ("localhost","u ser_name","user _password");

      change user_name and user_password with your user name and passord
      [color=blue]
      > if (!$link_id) {
      > echo ("Failed to connect to MySQL!");
      > exit;
      > }
      > else;
      > {
      > echo "Connected OK!";
      > }
      >
      > if (!mysql_select_ db("Wines")) {[/color]

      if (!mysql_select_ db("Wines",$lin k_id)) {
      [color=blue]
      > echo ("Failed to select database cms!");
      > exit;
      >
      > }
      > echo ("Connected to Database");
      > $resultset = mysql_query("SE LECT * FROM wine");[/color]

      $resultset = mysql_query("SE LECT * FROM wine",$link_id) ;
      [color=blue]
      > while ($row = mysql_fetch_row ($resultset)) {
      > echo "Date $row[0]: $row[1]\n";[/color]

      echo "Date ".$row[0].": ".$row[1]."\n";
      [color=blue]
      > }
      > echo ("end");
      > ?>
      > </html>
      > </BODY>
      > </HTML>
      >
      > And I have also tried:
      >
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      > <HTML>
      > <HEAD>
      > <TITLE> Getting PHP & MY SQL to work </TITLE>
      > </HEAD>
      >
      > <BODY>
      > <html>
      > <head>Wines PHP Tester<BR></head>
      > <body>
      >
      >
      > <?php
      > echo "This is PHP here....<BR>\n" ;
      > $connection = mysql_connect(" localhost");
      >
      > $db = mysql_select_db ("Wines",$conne ction);
      > $query = "SELECT * FROM Wine";
      > echo "Select..." ;
      > $result = mysql_query($qu ery,$connection );
      > echo "result..." ;
      >
      > ?>
      > </body>
      > </html>
      > </BODY>
      > </HTML>
      > But I get no results. It works fine in PHPmyAdmin though.
      >
      > I did have a different Mysql on my XPHome box which I have
      > subsequently deleted as it could not connect to the server once PHP
      > was installed.
      >
      > I am falling further behind in my degree as I can even get the db up
      > and running so I cant even get coding!
      >
      > Please please help.[/color]


      Comment

      • Geoff Berrow

        #4
        Re: Is my code for seeing a database wrong? Please help - getting very desperate!

        I noticed that Message-ID:
        <4e2d029c.03101 20215.3fd7cd5a@ posting.google. com> from James contained
        the following:
        [color=blue]
        >$link_id = @msql_pconnect( "localhost" );
        >if (!$link_id) {
        >echo ("Failed to connect to MySQL!");[/color]

        According to the manual, that function is used to make a persistent
        connection to MiniSQL Dunno if it works with MySQL.

        Try
        $db = mysql_connect(" localhost", "username", "password") ;

        if (!mysql_select_ db("Wines",$db) ) {
        echo ("Failed to select database");
        exit;
        etc.,etc.,
        --
        Geoff Berrow
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        Working...