Noob question re: oo vs procedural concepts
Posted: Fri Jan 02, 2009 11:36 am
Hi All,
I have included 2 sets of code copied right out of the PHP manual for the mysqli extension.
http://us2.php.net/manual/de/mysqli.connect.php
They both do the same thing. The difference is that one is oo styled and the other is procedural in nature.
I cannot get the oo code to work for me and I would really like to understand why.
Object Oriented version: this does NOT work for me.
Procedural version: this DOES work for me.
I am NOT looking for a workaround, I have that with the procedural code above.
Understanding why this particular oo code does not work for me would greatly help with my learning curve.
Note: I have been able to use other mysqli object members, so I know that mysqli extension is functioning.
Any help would be greatly appreciated.
Thanks in advance,
bartolo
I have included 2 sets of code copied right out of the PHP manual for the mysqli extension.
http://us2.php.net/manual/de/mysqli.connect.php
They both do the same thing. The difference is that one is oo styled and the other is procedural in nature.
I cannot get the oo code to work for me and I would really like to understand why.
Object Oriented version: this does NOT work for me.
Code: Select all
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_error) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", $mysqli->host_info);
/* close connection */
$mysqli->close();
?>Code: Select all
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", mysqli_get_host_info($link));
/* close connection */
mysqli_close($link);
?>I am NOT looking for a workaround, I have that with the procedural code above.
Understanding why this particular oo code does not work for me would greatly help with my learning curve.
Note: I have been able to use other mysqli object members, so I know that mysqli extension is functioning.
Any help would be greatly appreciated.
Thanks in advance,
bartolo