Jump to content

Is Anything Wrong With This Code ?


madsovenielsen

Recommended Posts

Hey all. i have installed and configured db2. i can connect succesfully. but i get a HTTP #500 Error when i try to create and populate a table. i use this code:

			<?php				$database = "TEST";				$user = "db2admin;				$password = "********";				$conn = db2_connect($database, $user, $password);				// Create the test table				$create = 'CREATE TABLE animals (id INTEGER, breed VARCHAR(32), name CHAR(16), weight DECIMAL(7,2))';				$result = db2_exec($conn, $create);				if ($result) {						print "Successfully created the table.\n";				}				else {					print "Cant create table!";				}				// Populate the test table				$animals = array(					array(0, 'cat', 'Pook', 3.2),					array(1, 'dog', 'Peaches', 12.3),   				array(2, 'horse', 'Smarty', 350.0),					array(3, 'gold fish', 'Bubbles', 0.1),					array(4, 'budgerigar', 'Gizmo', 0.2),					array(5, 'goat', 'Rickety Ride', 9.7),					array(6, 'llama', 'Sweater', 150)				);				foreach ($animals as $animal) {					$rc = db2_exec($conn, "INSERT INTO animals (id, breed, name, weight)					  VALUES ({$animal[0]}, '{$animal[1]}', '{$animal[2]}', {$animal[3]})");   				if ($rc) {						print "Insert... ";					}			}		?>

i have disabled freindly HTTP errors but i still get the plain. HTTP 500 - Internal Server Error the user i use to connect to the database have all privileges granted. any thoughts is very appriciated/mads

Link to comment
Share on other sites

Add this to the top of your page:error_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);If it's returning a 500 error you should see the error message, just printed out on a plain white page. If you see something other than an error message on a plain white page, try it in a different browser.

Link to comment
Share on other sites

Add this to the top of your page:error_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);If it's returning a 500 error you should see the error message, just printed out on a plain white page. If you see something other than an error message on a plain white page, try it in a different browser.
i added the code to my php script. i still get the HTTP #500 error. in Firefox i just get a blank page.
Link to comment
Share on other sites

Is there a syntax error? Create another file to turn on error reporting and then include your other file.

<?phperror_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);include 'page.php';?>

Link to comment
Share on other sites

Is there a syntax error? Create another file to turn on error reporting and then include your other file.
<?phperror_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);include 'page.php';?>

That worked. im getting this.Parse error: syntax error, unexpected T_STRING in C:\Programmer\Apache Software Foundation\Apache2.2\htdocs\db.php on line 17its the password. i know the password to be 100% correct. it must be the configuration of db2. you are are a php guru. nothing less. :) thanks alot
Link to comment
Share on other sites

A parse error means the PHP isn't formed correctly. You're missing a quote here:$user = "db2admin;
never mind. i got the error because the table was already created. its working now. thanks alot for your help./mads
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...