SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP MySQL error on valid query

    I'm getting an error in PHP on a valid query, which executes fine when run directly from PHPMyAdmin.

    Has anyone had a similar problem before and could point me in the right direction?

    The error is below along with the function used the execute the query.

    PHP Code:
    Array
    (
        [
    Error] => Invalid Query SELECT FROM users ORDER BY userDeleted ASCuserFullname ASC
    )
    Array
    (
        [
    Error] => Empty MySQL resource.
    )

    public function 
    query($q){
            if(empty(
    $q)) $this->dbError('Empty MySQL Query.');
            if(
    $this->linkID == 0$this->connect();
            
    $temp = @mysql_query($q$this->linkID);
            if(!
    $temp$this->dbError('Invalid Query : '.mysql_error().'<br />'.$q);
            return 
    $temp;

    }

    public function 
    getUsers(){
        
    $q "SELECT * FROM users ORDER BY userDeleted ASC, userFullname ASC";
        
    $result $this->query($q); 
    Cheers,
    Rhys

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,888
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Try this:

    PHP Code:

     $temp 
    = @mysql_query($q); 
    //
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  3. #3
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but that didn't solve it. The strange thing is, this system works. It works on other sites and works here in some instances. I can log in, but I can't select from a certain table. Strange and something I've not seen before.

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,888
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    The error returned states that you do not have a valid MySql connection.

    PHP Code:
    //  [Error] => Empty MySQL resource. 


    // try to connect     to database using username and password
       
    $dbh = @ mysql_connect
      
    (
        
    $hostname,
        
    $username,
        
    $password
      
    );
      if(
    mysql_error())    
        echo 
    __LINE__,    mysql_error();                
        
        
    // try to select database
       
    $connected = @ mysql_select_db ($database);
       if (
    mysql_error()) 
         echo 
    __LINE__,    mysql_error(); 
    //
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all avoid suppressing the warnings by using '@'.

    Can you post the whole class and/or the area of code where you have made the mysql server connection?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •