PHP to MySQL Problem

I’m no PHP expert, but I believe the problem with this script is using it with PHP 5, but I really can’t tell. Please help.

[code]<?php
Define(‘DATABASE_SERVER’, ‘12.34.56.789’);
Define(‘DATABASE_USERNAME’, ‘myName’);
Define(‘DATABASE_PASSWORD’, ‘myPassword’);
Define(‘DATABASE_NAME’, ‘myDB’);

class AppointmentsService {
private $mysqli;
private $err_prefix="Remoting Error: ‘myService’ class database ";

public function __construct() {
	error_reporting(0);	# Silence error messages and return them to WebORB
	# Connect to MySQL database....
	$this->mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);         
	if (mysqli_connect_errno()) {
		$msg=$this->err_prefix."could not connect: ".mysqli_connect_error();
	throw new Exception($msg);
}
}


public function getData($year, $month) {
	if (!$result=$this->mysqli->query("SELECT * from myData WHERE year='$year' AND month='$month'")) {
		$msg=$this->err_prefix."SELECT query error: ".$this->mysqli->error;
		$this->mysqli->close();
	throw new Exception($msg);
	}
	while ($row = $result->fetch_assoc()) {
		$search_array[] = $row;
	}
	return($search_array);
}

}

?>[/code]

MOD EDIT: Added code tags.

What’s the problem with the code? What does it do that it should not, or what does it not do that it should? Are you getting any errors? If yes, did you google those errors? What did you find with google? Have you tried debugging (see my signature)? What was your conclusion while debugging? Which line(s) were indicated by the errors, and which line(s) are you suspecting could be the problem? Have you read up on the difference between PHP4 and PHP5 for the functions you’re using? Did you find any relevant discrepancies there? How did you deal with those in your script?

As you can see, I have lots of questions only you can answer. It’s not-done and rude to post your script and say ‘can you fix it’. We expect your effort.

I inderstand your point. The issue is that I know almost nothing about PHP. This script was modified for me in PHP 4 for a few $$, but that person is no longer available. I’m using this script with Adobe Flex to communicate with a MySQL database, but my hosting company upgraded to 5 and this script stopped working. I really don’t even know where to start.

Why don’t you first start debugging? Tell us what you’ve tried, what the results were, and what the conclusions are you’re drawing from those results. If it’s a PHP4 vs. PHP5 version, then it’s probably one of the functions you’re using (or the class structure, as PHP4 only has minimal OOP support). Error_reporting() for example, should be able to give you tons of information about your script.

Sponsor our Newsletter | Privacy Policy | Terms of Service