I'm pretty new to PHP, but I've been using ASP for years... it's just that my new company doesn't have a Microsoft webserver, so I'm trying to learn something new...

Anyways, I'm trying to make a database connection, and I know I am getting some sort of error, but it isn't displayed anywhere on the page or in the code.

I read that you had to set things in the PHP.ini file, but I cannot see this file in my directory structure, so I ran the below command...

<? phpinfo(); ?>

Which gives me a bunch of info about my site, and it turns out that the php.ini file is located above the directory structure, where i cannot get to it...

Our website is hosted by the same comany that does our internet access (package deal) and I have been unable to contact them (maybe they're on thanksgiving break???).

So is there something else I can do to get this to work? I just want to be able to tell where I am screwing up... preferably, I'd like to display all errors for development purposes.

    Set
    error_reporting(E_ALL);

    at the top of the script you wish to test.

      I put that in, but I'm not seeing any errors... the page just seems to stop executing at the point where I connect to my database, which I assume is because of an error.

      This is the code block...

      <?

      $db = 'database\jobs.mdb';
      $conn = new COM('ADODB.Connection');

      $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");

      $sql = 'SELECT * FROM JobListing';
      $rs = $conn->Execute($sql);

      ?>

      And using Echos, I found it just stops at the $rs=$conn-> line.

      I placed this just after the body section then...

      <?

      error_reporting(E_ALL);

      ?>

      Does it need to be at the top??? All I have is crummy Frontpage which doesn't like PHP and keeps moving it back into the body when I save.

        Should I be posting this in a differant forum? I'm getting no love here 🙁

          Originally posted by Kris5.0
          Should I be posting this in a differant forum? I'm getting no love here 🙁

          If love's what you're after, yes.

          As for the PHP, can you access the web server error logs?

            Originally posted by Kris5.0 Does it need to be at the top??? All I have is crummy Frontpage which doesn't like PHP and keeps moving it back into the body when I save. [/B]

            Yes, set error_reporting at the top.

            And if Frontpage is crummy (and I tend to agree), try Notepad. Seriously. Or look in the "Echo Lounge" for the "Editor used for PHP" thread, which has about two gazillion ideas on editors and IDE's you can use for coding.

            HTH,

              error_reporting)E_ALL); does need to go at the top of your file. But try checking for an error after the Open statement. You will have to look at the documentation for details.

              There should also be a way to check to see if the new COM statement worked. The manual shows checking for NULL but that's not right. Try looking for an example.

                Originally posted by dalecosp
                If love's what you're after, yes.

                As for the PHP, can you access the web server error logs?

                No, I cannot access them... they too are above the structure I can get at... I will talk with my host next week, they appear to be on Thanksgiving vacation this week.

                Yes, set error_reporting at the top.

                And if Frontpage is crummy (and I tend to agree), try Notepad. Seriously. Or look in the "Echo Lounge" for the "Editor used for PHP" thread, which has about two gazillion ideas on editors and IDE's you can use for coding.

                I could do notepad... problem is, I can't upload my files... I tried FTPing to the site and could not log in (got generic 'Error, could not connect' message), the only way I've been able to get in so far is by using Frontpage, which is the only way anyone around here anyone has ever done it (it works for them because they all use straight HTML, nothing fancy like I want to do).

                  Okay, I got the up top now but I still see no errors (Windows saved that site as a web and I was able to go to My Network Places and open it, then I could copy out files i wanted to change, change them with notepad, and copy them back)...

                  Shouldn't I be able to see errors right on screen when they occur??? Like, printed right into the HTML page? That is the way ASP works and I was hoping to see something similar.

                    Depends how the server is set up. To be honest, it's not a good idea displaying errors to screen on a live server, that's why dalecosp was asking if you have access to the webserver logs. Many web hosts disable the display of errors and instead write them to the error logs. Unless you can install the relevant software on your local machine (PHP, Apache, database, etc.) you're going to have to catch errors and display them yourself. This is what ahundiak was getting at. I suggest reading the documentation for the API you're using or a bit of crude debugging (reading the docs is always the best idea but I'm bored 😉)

                    <?php
                    
                    $db = 'database\\jobs.mdb';
                    $conn = new COM('ADODB.Connection');
                    if($conn==false || $conn==null) {
                      exit('The script failed while instantiating the class');
                    }
                    
                    
                    if(!$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db")) {
                      exit('The script failed while opening the connection');
                    }
                    
                    $sql = 'SELECT * FROM JobListing';
                    if(!$rs = $conn->Execute($sql)) {
                      exit('The script failed while executing the query');
                    }
                    ?> 
                    

                    This debugging code won't tell you much but it will, at least, tell you where to focus your reading 🙂

                    Cheers
                    Rob

                      Is there any way I can make it spit out exactly what error I am receaving? I can print output to the screen to find where my error is, but it makes it hard to solve when I don't know what my error is (can't open database, can't find database, wrong driver, ect). I don't really care if it's a bad idea, I can turn it off later when the program is acctually used, but right now I'm the only one doing anything with it.

                      It's error on this statement by the way...

                      $conn = new COM('ADODB.Connection');

                      Is it possible my server is setup to not allow me to create a COM object??? Any way I can find this out?

                      ...

                      I tried doing one of those error catches for that line...

                      if (!$conn = new COM("ADODB.Connection"))
                      exit("Unable to create an ADODB connection<br>");

                      And it never prints the 'Unable to creat...' message, yet I have a line of text printing to screen imediatly afterward and that text is never printed.

                        You could try doing a print_r on $conn, I'm afraid I haven't used COM .... hang on a minute. You say the server isn't a windows box right, and you're trying to use COM, a Windows only extension. I think we may have found your problem.

                          Originally posted by bubblenut
                          You could try doing a print_r on $conn, I'm afraid I haven't used COM .... hang on a minute. You say the server isn't a windows box right, and you're trying to use COM, a Windows only extension. I think we may have found your problem.

                          You know, that's probably it. All the examples I've been able to find use a com object to connect to the Access database though...

                          I'd still like to use an Access database if possible. We unfortunatly don't seem to have mySQL installed, so I need something and Access would work good... our traffic isn't that high and I really just need something I can upload without having to install anything on the server.

                          Would XML be a good solution to use instead? All I need to do is simple select, insert, delete, and modify statements. The database is never going to be that big (we're gonna use it to post jobs, which we don't do very often).

                            If the server isn't Windows were you hoping to connect to a remote Access database? Is there no database system on your host at all? If not then, if you're using php5 then you can use SQLite. Otherwise XML with DOM, although unless your data's pretty simple and pretty small, that could get hectic.

                            HTH
                            Bubble

                              Originally posted by bubblenut
                              If the server isn't Windows were you hoping to connect to a remote Access database? Is there no database system on your host at all? If not then, if you're using php5 then you can use SQLite. Otherwise XML with DOM, although unless your data's pretty simple and pretty small, that could get hectic.

                              HTH
                              Bubble

                              No, it would be a local database.

                              The server I am using is provided by our internet provider, so I can only use what they have. They do not appear to have any databases setup. If SQLite can be used without having to perform an install procedure (ie, I can just upload it and then it's ready to use), I could use that... this is why I was going to use Access.

                              Otherwise, it's XML for me... it's not too complex (couple text fields, couple date fields) so that might work.

                                Write a Reply...