Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2009, 06:44 AM
Authorized User
 
Join Date: Jun 2009
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default OOPS - MySQL

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\n", mysqli_connect_error());
exit();
}


if ($result = $mysql->query("SELECT title FROM push_content LIMIT 10")) {
printf("Select returned %d rows.\n", $result->num_rows);

/* free result set */
$result->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.
__________________
Thanks & regards
Lokananth
[url "http://www.mioot.com"]Live Chat Software[/url] By miOOt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Oops ! sandeepgreaternoida BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 April 3rd, 2009 03:46 AM
oops with c#.net sureshmm General .NET 8 March 22nd, 2007 10:43 PM
oops with c#.net sureshmm ASP.NET 1.0 and 1.1 Basics 3 March 21st, 2007 11:58 AM
Oops, wrong subject! Aaron Edwards ASP.NET 2.0 Basics 0 September 13th, 2006 07:37 PM
OOPs bijgupt C# 5 May 18th, 2006 05:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.