Re: [PHP-DB] Nothing returned

2001-11-04 Thread Jesse Goerz

On Saturday 03 November 2001 17:29, Martin wrote:
 Why am I not getting anything returned from this function?
 I have code doing a if user exists and b if user doesn't
 exist. I'm not getting any numRows result apparently. The
 query is OK and returns 1 user for $name=admin. I'm not
 getting any errors from isError.

 Martin

 function exists($name)
 {

 $sql = SELECT * FROM users WHERE
 (name='$name'); $res = $db-query($sql);
 if (DB::isError($res)) {
 die ($res-getMessage());
 }
   ---if($res)
 {
 $Rows = $res-numRows();
 if($Rows  0)
 {
 return(TRUE);
 } else
 {
 return(FALSE);
 }
 }
 }

If you're not getting any errors it's either a logic error or 
your sql statement is messed up.

1.  Is the line I marked above always testing false?  Put some 
prints or echos inside the if conditions and test your logic.
2.  Log in to the mysql server and run your query directly with 
the value you expect.  Do you get the results you're looking for?
3.  Test the variable in the SQL statement with a print or echo. 
 Are you actually passing what you think to $sql?

HTH,
Jesse


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Objects in dbm db

2001-10-20 Thread Jesse Goerz

I'm trying to store an array of objects in a dbm database.  
Here's what I'm using:
function build_preliminary_language_index($lang, $db, $key) {
$dbh = dbmopen($db, c) 
or die(Error opening db);
$article_string = dbmfetch($dbh, articles);
$article_array = unserialize($article_string);
$lang_index = array();
for($i=0; $i  sizeof($article_array); $i++) {
  if(stripslashes($article_array[$i]-get_lang()) == $lang) {
array_push($lang_index, $article_array[$i]);
  }
}
$lang_string = serialize($lang_index);
dbmreplace($dbh, $key, $lang_string);
dbmclose($dbh)
}

Which seems to work nicely.  I was able to grab the newly 
created array $lang_string from another page and output the 
information easily.  The problem is I'm grabbing the new array 
and manipulating it with another function below and it keeps 
tacking on a NULL as the first element of the array:

Here's some debugging output and the error on the html page:
array
$article_array[0] = NULL
$article_array[1] = object

Fatal error: Call to a member function on a non-object in 
/home/jesse/public_html/newbiedoc/devel/index.es.phtml on line 
205

Line 205 is where the objects start getting utilized and it 
barfs on the NULL.  Here's the function I'm calling to 
manipulate the array of objects after it has been created and 
inserted in the database:

function build_language_specific_index($lang, $db, $key) {
error_reporting(E_ALL);
$dbh = dbmopen($db, c)
or die(Error opening db.);
$lang_string = dbmfetch($dbh, $key);
$en_string = dbmfetch($dbh, en_index);

$lang_index = unserialize($lang_string);
$en_index = unserialize($en_string);

$size_lang_index = sizeof($lang_index);
$size_en_index = sizeof($en_index);

for($i=0; $i  $size_lang_index; $i++) {
for($j=0; $j  $size_en_index; $j++) {
   if($lang_index[$i]-get_aid() != 
$en_index[$j]-get_aid()) {
array_push($lang_index, $en_index[$j]);
   }
}
}
$lang_string = serialize($lang_index);
dbmreplace($dbh, $key, $lang_string);
dbmclose($dbh);
}

I realize that MySQL or a rdbms would probably solve all these 
issues but I don't have that option yet.  I do have the class 
definition included in both the pages so that doesn't seem to be 
an issue.  I have read the information on serialized objects but 
I confess that I'm not grasping it all that well.  Any help 
would be greatly appreciated.

Thanks,
Jesse


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]