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
https://forums.phpfreaks.com/topic/92404-php-mysql-connection-and-query/
Share on other sites

Archived

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

×
×
  • 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.