Adodb, Select Like no result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Adodb, Select Like no result

Post by salsa »

Hey guys...

i have a problem when i try to execute a SELECT...

1. i print that code...

Code: Select all

print trim(substr($v['nome'], 6, 15));
and he return "noronha"

ok... after i run my SQL

Code: Select all

 
$sql = "SELECT * FROM intra_user WHERE nome LIKE '%" . trim(substr($v['nome'], 6, 15)) . "%'";
$rs = $this->db->conn->Execute($sql) or die("Error in query: " . $this->db->conn->ErrorMsg());
 
ok .. no error results ... and no result in my select...

but... if i get SQL code and put on my phpmyadmin he return results...



example...

if i use...

Code: Select all

 
$sql = "SELECT * FROM intra_user WHERE nome LIKE '%noronha%'";
$rs = $this->db->conn->Execute($sql) or die("Error in query: " . $this->db->conn->ErrorMsg());
 
i get results... but if i use trim(substr($v['nome'], 6, 15)); i dont receive any result and any errors..

why?

:(

thanks
Last edited by salsa on Fri May 16, 2008 11:54 am, edited 2 times in total.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Adodb, Select Like no result

Post by Jade »

Hey there,

I don't think its a problem with using the trim inside of the query. It looks to me that the problem is you're not fetching the results from the query and storing them anywhere. For instance:

Code: Select all

 
<?php
 
$result = mysql_query("SELECT * from Tablename");
 
//if you leave this out $row won't have a value
$row = mysql_fetch_array($result);
 
echo $row['fieldname'];
 
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Re: Adodb, Select Like no result

Post by salsa »

Hey, thanks to reply my post...

When i execute i execute fetch in adodb using geRows ... but no results...

Code: Select all

 
<?
foreach ($rs->getRows() as $row) {
    print $row['id']."<br>";
}
?>
 
but in phpmyadmin ... select works fine... :/
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Adodb, Select Like no result

Post by Jade »

Try doing this and see what's actually in $rs. Maybe you're accessing something that isn't there.

Code: Select all

 
print_r($rs);
print_r($rs->getRows());
 
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Re: Adodb, Select Like no result

Post by salsa »

hey Jade...

nothing in $rs ... but if i get SQL code and put on phpMyAdmin .. i get results :/

i try to change adodb to mysql_connect, mysql_select_db and mysql_query but i got same error :/
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Adodb, Select Like no result

Post by Jade »

Try this:

Code: Select all

 
$v['nome'] = "something";
 
mysql_connect("localhost", "username", "pass")
or die ('there was a connection error: ' . mysql_error());
 
mysql_select_db("tablename")
or die ('there was a table select error: ' . mysql_error());
 
$result = mysql_query("SELECT * FROM intra_user WHERE nome LIKE '%" . trim(substr($v['nome'], 6, 15)) . "%'")
            or die ('there was an error: ' . mysql_error());
 
$row = mysql_fetch_array($result)
or die ('mysql array fetch error: ' mysql_error());
print_r($row);
 
It sounds like you're having problems a) connecting to the database or b) getting info from the table. Try running this code, it will tell you where exactly you problem is and you can go from there.
From
Last edited by Jade on Thu May 29, 2008 3:00 pm, edited 1 time in total.
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Re: Adodb, Select Like no result

Post by salsa »

i got:

mysql array fetch error:

and no msg... :p

but if i print

Code: Select all

print "SELECT * FROM intra_user WHERE nome LIKE '%" . trim(substr($v['nome'], 6, 15)) . "%'";
and put on phpmyadmin and run.... he running ok :p
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Adodb, Select Like no result

Post by Jade »

Sorry, its an error in the code I gave you. Change this line:

Code: Select all

 
or die ('mysql array fetch error: ' mysql_error());
 
To this:

Code: Select all

 
or die ('mysql array fetch error: ' . mysql_error());
 
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Re: Adodb, Select Like no result

Post by salsa »

relax jade...

i fix that small error before run that script... :)

so i got error :(
salsa wrote:i got:

mysql array fetch error:

and no msg... :p

but if i print

Code: Select all

print "SELECT * FROM intra_user WHERE nome LIKE '%" . trim(substr($v['nome'], 6, 15)) . "%'";
and put on phpmyadmin and run.... he running ok :p
User avatar
salsa
Forum Newbie
Posts: 6
Joined: Fri May 16, 2008 9:26 am
Location: Brazil - São Paulo/SP
Contact:

Re: Adodb, Select Like no result

Post by salsa »

Code: Select all

 
set_time_limit(0);
$handle = @fopen("temp/myfile.txt", "r");
 
while (!feof($handle)) {
    $linha = fgets($handle, 4096);
    mysql_connect('localhost', 'myuser', 'mypass') or die ('there was a connection error: ' . mysql_error());
    mysql_select_db(DATABASE) or die ('there was a table select error: ' . mysql_error());
    $result = mysql_query("SELECT * FROM intra_user WHERE nome LIKE '%" . trim(substr($linha, 6, 15)) . "%'") or die ('there was an error: ' . mysql_error());
    $row = mysql_fetch_array($result) or die ('mysql array fetch error: ' . mysql_error());
    print_r($row);      
}
fclose($handle);
 
return...... "mysql array fetch error: "

anybody can help me? :(
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Adodb, Select Like no result

Post by Jade »

Sounds like something is wrong with your mysql maybe? I'm not sure, can you get it to query for other things outside of phpmyadmin?
Post Reply