1

I am executing the following commands in my model php in Codeigniter:

$sql=mysql_query("select name from reseller_domain where name='".$name."'");
$numrows=mysql_num_rows($sql);
if($numrows!=null || $numrows==0)
{
  return 'f';
}
else
{
 return 't';
}

I am not getting any result whatsoever. However, the same query is running perfectly fine in phpmyadmin.

2

4 Answers 4

2

1. mysql_* is deprecated so avoid using that...
2. Are you executing the mysql_connect() command first?
3. Your code is prone to sql injection


4. Since you are using codeIgniter, Im assuming you want to use the CodeIgniter framework to access your database

Have a look here on how to use codeigniter to access your database. In short:

  1. Configure CI by adding your database settings
  2. Try this in CodeIgniter

     $sql = "select name from reseller_domain where name = ?";
     $this->db->query($sql, array($name));
     if($query->num_rows() == 0){
         return 'f';
     }else{
         return 't';
     }
    
Sign up to request clarification or add additional context in comments.

3 Comments

@user3126593 Did you configure codeigniter with your database settings?
of course yes. This is the only that is not working for me. All others are working fine.
@user3126593 Can you tell us what errors you get? You can check using the way echo_Me said
1

try that and see what error you got.

  $sql=mysql_query("select name from reseller_domain where name='".$name."'") or die(mysql_error());

edit:

why you check like that ?

try check like that:

   if($numrows==0)
    {

3 Comments

I want to check whether there are any rows returned or not. If number of rows returned is 0, then I want to return a false.
try that iff it works select name from reseller_domain where name='Yourname' give yourname with an exisitng name and see if it work.
even tht doesn't return a result.. I tried using an existing name from the table.
1

Edit: Seriously my man, you need to start using the CI DB class, this is not a good practice. First of all, try getting your query in a var and exit it to the screen. Then see what the actual query gets and try this in your PHPMYADMIN. I suspect errors with the $name var.

===========================================================================

It looks like you didn't select a database.

Try using Code Igniters DB class?

If you don't already do,

$this->db->query('select name from reseller_domain where name='".$name."');

Must say though you'd better read the docs about it, it might help you a little further. If you did the query with the CI Db class you might want to see the actually outputted query with:

exit($this->db->last_query()); //yes exit isn't good, not even for debugging. But it works.

Then see what goes wrong inside of your query.

2 Comments

I tried the CI DB way too. Even that didn't return any result. :(
Then try to put your query in a var first. $query = 'SELECT etc' and then exit $query;. Look at the query and use it in PHPMYADMIN. What result you get?
0

It is possible that your DB setup in codeigniter, and where you were in phpmyadmin are using a different default schema.

Try it with: "select name from database_name.reseller_domain where name='".$name."'"

2 Comments

Nope, there is only one database that I am connecting to. It is working fine for all other queries. Even for this query, it worked yesterday. But today it suddenly stopped working. I am unable to figure out the issue. Anyway, I tried your suggestion. Still not result.
Hey buddy, thanks for your advise. Your answer is not fully correct but it was very close. I had to use a 'tank_auth' prefix to the table name. And the issue was solved. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.