# OOPS - MySQL

**URL:** <https://forum.kirupa.com/t/oops-mysql/293958>\
**Category:** programming\
**Created:** [August 6, 2009, 9:35am UTC](https://forum.kirupa.com/t/oops-mysql/293958 "2009-08-06T09:35:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertsavier](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://forum.kirupa.com/u/gilbertsavier)\
**Post date:** [August 6, 2009, 9:35am UTC](https://forum.kirupa.com/t/oops-mysql/293958/1 "2009-08-06T09:35:21Z")

</div>

Hey guys,  
I am looking for help with my OOPS code for connecting to MySQL, just for people that don’t know what OOPS is Object Oriented Programming.

I am trying to connect to my database (MSQL) using this technology, however all my coding just does not seem to be working

The first code I tried was this one, however since i am on a shared server it seems that mysqli does not work??? DONT ask me why.  
and as i am trying to make something for other site owners to use i need it to work with out them having to contact there administrators asking them to allow mysqli  
$mysqli = new mysqli(“localhost”, “desvisa\_v”, “\*\*\*\*\*\*”, “desvisa\_site”);

/\* check connection \*/  
if (mysqli\_connect\_errno()) {  
printf("Connect failed: %s  
", mysqli\_connect\_error());  
exit();  
}

if ($result = $mysql-\>query(“SELECT title FROM push\_content LIMIT 10”)) {  
printf("Select returned %d rows.  
", $result-\>num\_rows);

```
/* free result set */
$result-&gt;close();

```

}

$mysqli-\>close();  
My second code, well i did not make the code, just copied and paste, BUT man it is way to confussing and i am just not understanding it.  
class MyDatabase  
{  
// The var that stores the last  
// used SQL statement  
var $SQLStatement = “”;

// The var that stores the error  
// (if any)  
var $Error = “”;

function MyDatabase()  
{  
// Config for the database  
// connection  
$this-\>DBUser = “desvisa\_v”;  
$this-\>DBPass = “\*\*\*\*\*”;  
$this-\>DBName = “desvisa\_site”;  
$this-\>DBHost = “localhost”;  
}

function Connect()  
{  
//Connect to a mysql database  
$this-\>db = mysql\_connect($this-\>DBHost,  
$this-\>DBUser, $this-\>DBPass) or  
die("MYSQL ERROR: ".mysql\_error());  
// Select the database  
mysql\_select\_db($this-\>DBName,  
$this-\>db) or die("MYSQL ERROR:  
".mysql\_error());  
}

// Disconnect from the MYSQL database  
function Disconnect()  
{  
mysql\_close($this-\>db) or die("MYSQL  
ERROR: ".mysql\_error());  
}  
}  
So if any one can come up with a OOPS way to connect to a mysql database, I would be forever in your debt.
