OOP in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear my friends,

This is the first time for me to use OOP concept of PHP. I wrote still a very simple codes but it doesn't work as my manual book taught. the book titled "MySQL/PHP Database Application" by Jay Greenspan say these lines should work but in fact it don't work as expected.
Here is my code:
===============================
//pelangganbaru.php
<?php
require "koneksi.php";
$sqlnya="select country from countries";
$klas=new koneksi($sqlnya);
?>
===============================
//koneksi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
  <META name="generator" content="HTML Tidy for Linux/x86 (vers 31 October 2006), see www.w3.org">

</HEAD>

<BODY>
<?php
class koneksi{
$namakompie="127.0.0.1";
$un="root";
$pw="mysqlpw";
$sqlnya;
$kueri;

function koneksi($sqlnya){
echo "superclass koneksi dipanggil<br>";
$konek=mysql_connect("$namakompie","$un","$pw");
if ($konek){
	echo "koneksi berhasil (connection succeeded)<br>";
	$mybd=mysql_select_db("survey",$konek);
	$kueri=mysql_query($sqlnya,$konek);
}else{
	echo "I can't talk to the server<br>";
	exit();
}
return $kueri;
}

}
?>
</BODY>
</HTML>
=====

Theoritically if Class "koneksi" is being initialized than it prints "koneksi berhasil (connection succeeded)" but it doesn't.

Please tell me what is my mistake.

Thank you very much in advance.
-- 
Patrik Hasibuan <patrikh@xxxxxxxxxxxxxxxxxxxxx>
Junior Programmer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux