PDA

View Full Version : mysql_fetch_object mystery (php5)



jwopitz
January 14th, 2008, 05:13 PM
Hi, folks.

I am rather new to PHP. I am creating an application where I am using AMFPHP, Flex and MySQL.

On one of my php methods I am trying to return a value object or a mysql query.


return mysql_fetch_object($result);This returns a simple object with the properties of the object set to that data retrieved in the database (as expected). However I want to be able to do this:


return mysql_fetch_object($result, "UserVO");When doing so it returns the expected object type (a UserVO), however it returns the values of the UserVO to their initialized values which are various strings. It is not setting the values of the properties to that which are found in the database.

Here is my UserVO php class:

<?php
class UserVO
{
var $_explicitType = "UserVO";

var $id = 0;
var $userName = 'userName';
var $password = 'password';
}
?>

What am I missing here? Again I am a complete PHP noob.

borrob
January 15th, 2008, 08:15 AM
i think this function could help:

function print_vars($obj)
{
foreach (get_object_vars($obj) as $prop => $val) {
echo "\t$prop = $val\n";
}
}

when calling this function with the resulting object you can echo out all member vars of your object.
The problem that you have could be encountered by case sensitivity because the data binding is case sensitive. Members that are not already in your object are being added...

jwopitz
January 15th, 2008, 04:08 PM
Back again. So I figured out what the issue was. You can read the original posting here: http://www.phpfreaks.com/forums/index.php/topic,177189.0.html

To sum it up, it was my collation and case-insensitive columns assigning the values on properties that were named in camelCase.

jwopitz
January 15th, 2008, 04:10 PM
So I guess I need to know a bit more about MySQL.

If I care about my tables' columns' names and their stored values being case-sensitive, what is the best collation to use? UTF8_bin? Also should I just assign the whole DB to use that collation by default or should it be a case by case (or rather a column by column) basis?