Jump to content

PHP-MySQL Connection and Query


jmfillman

Recommended Posts

I am a PHP newbie, but I believe this is not working because of PHP 5, was working on PHP 4  ???. Also, if this could be cleaned up or improved, I really would appreciate any help you can offer.

 

<?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);

}

 

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.