Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    mysqli query not working

    Okay trying to use mysqli this time, but I cant seem to get the query working through the class.

    PHP Code:
    $SC_query $arcade_db->query("SELECT * FROM site_config");
    $SC_row mysql_fetch_array($SC_query); 
    PHP Code:
    public function query($query){
    $this->result mysql_query($query,$this->mysql);
    return 
    $this;

    I don't notice anything wrong so far.

    Thanks

  • #2
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Decided to do it this way.


    PHP Code:
    public function query($query) {
            
            
    $result mysql_query($query$this->mysql);
            
            if (!(
    $result)) {
                
    ob_end_clean();
                die(
    "SQL Error: ".mysql_error($this->mysql)."<br /> Query: $query<br />");
            }
        return 
    $result;
        } 
    Still dont know yet what I was doing wrong above, its probably something small and will notice it soon.

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post

    Quote Originally Posted by sitNsmile View Post
    Okay trying to use mysqli this time, but I cant seem to get the query working through the class.

    PHP Code:
    $SC_query $arcade_db->query("SELECT * FROM site_config");
    $SC_row mysql_fetch_array($SC_query); 
    PHP Code:
    public function query($query){
    $this->result mysql_query($query,$this->mysql);
    return 
    $this;

    I don't notice anything wrong so far.

    Thanks
    You said you where using mysqli shouldn't your query be;

    PHP Code:
    mysqli_query
    mysqli_fetch_array 

  • #4
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    Quote Originally Posted by djdubuque View Post
    You said you where using mysqli shouldn't your query be;

    PHP Code:
    mysqli_query
    mysqli_fetch_array 
    That wot i was just thinking :P

  • #5
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by mic2100 View Post
    That wot i was just thinking :P

    yeah I've actually tired that after you mentioned it. But don't think that had much to do with it, or maybe I am confused with classes and what mysql or mysqli differences.

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Not sure about your full code but I did find this, does this make sense?

    PHP Code:
      <?php
    $link 
    mysqli_connect("localhost""my_user""my_password""world");

    /* check connection */
    if (mysqli_connect_errno()) {
        
    printf("Connect failed: %s\n"mysqli_connect_error());
        exit();
    }

    $query "SELECT Name, SurfaceArea from Country ORDER BY Name LIMIT 5";

    if (
    $result mysqli_query($link$query)) {

        
    /* Get field information for column 'SurfaceArea' */
        
    $finfo mysqli_fetch_field_direct($result1);

        
    printf("Name:     %s\n"$finfo->name);
        
    printf("Table:    %s\n"$finfo->table);
        
    printf("max. Len: %d\n"$finfo->max_length);
        
    printf("Flags:    %d\n"$finfo->flags);
        
    printf("Type:     %d\n"$finfo->type);

        
    mysqli_free_result($result);
    }

    /* close connection */
    mysqli_close($link);
    ?>

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,335
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by sitNsmile View Post
    Okay trying to use mysqli this time, but I cant seem to get the query working through the class.

    PHP Code:
    public function query($query){
    $this->result mysql_query($query,$this->mysql);
    return 
    $this;

    as already mentioned, if you start with mysqli, you cannot use mysql_* functions (kinda obvious, ain’t it?).

    if you like object oriented style, why not using the OOP style of MySQLi?

    PHP Code:
    $db = new MySQLi($host$user$pass);
    $db->query(); 
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #8
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Dormilich View Post
    as already mentioned, if you start with mysqli, you cannot use mysql_* functions (kinda obvious, ain’t it?).

    if you like object oriented style, why not using the OOP style of MySQLi?

    PHP Code:
    $db = new MySQLi($host$user$pass);
    $db->query(); 
    yes that is already in process. I thought I was already doing that?

  • #9
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by djdubuque View Post
    Not sure about your full code but I did find this, does this make sense?

    PHP Code:
      <?php
    $link 
    mysqli_connect("localhost""my_user""my_password""world");

    /* check connection */
    if (mysqli_connect_errno()) {
        
    printf("Connect failed: %s\n"mysqli_connect_error());
        exit();
    }

    $query "SELECT Name, SurfaceArea from Country ORDER BY Name LIMIT 5";

    if (
    $result mysqli_query($link$query)) {

        
    /* Get field information for column 'SurfaceArea' */
        
    $finfo mysqli_fetch_field_direct($result1);

        
    printf("Name:     %s\n"$finfo->name);
        
    printf("Table:    %s\n"$finfo->table);
        
    printf("max. Len: %d\n"$finfo->max_length);
        
    printf("Flags:    %d\n"$finfo->flags);
        
    printf("Type:     %d\n"$finfo->type);

        
    mysqli_free_result($result);
    }

    /* close connection */
    mysqli_close($link);
    ?>
    Makes sense, yes. But I am trying to build the mysql class to allow me to run multi database (2 database) on 1 site.

  • #10
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,335
    Thanks
    13
    Thanked 348 Times in 344 Posts
    Quote Originally Posted by sitNsmile View Post
    I thought I was already doing that?
    didn’t look like that.

    Quote Originally Posted by sitNsmile View Post
    Makes sense, yes. But I am trying to build the mysql class to allow me to run multi database (2 database) on 1 site.
    something like that?
    PHP Code:
    $db1 = new MySQLi();
    $db2 = new MySQLi(); 
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #11
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Dormilich View Post
    didn’t look like that.



    something like that?
    PHP Code:
    $db1 = new MySQLi();
    $db2 = new MySQLi(); 
    Yeah I've tried that, and yet it always plays the database added last as the default. I tried different ways to only fetch queries on specific databases, but doesn't listen to it. Still looking into defining that, have code or resource that could speed that up, would be great, I'll keep testing.

  • #12
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,335
    Thanks
    13
    Thanked 348 Times in 344 Posts
    I usually use PDO and only one DB, so I don’t know for sure.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Treat mysqli as an object and you can 'jail' it to its particluar instance. Otherwise, all mysql and mysqli procedural methods include a reference for a $link_id or $resouce_id. This refers to you're connection itself, and if not present it will use the last one available.
    PHP Code:
    $db1 = new MySQLi(...); 
    $db2 = new MySQLi(...); 

    $db1->query('SELECT ....'); // Uses the $db1 connection
    mysqli_query('SELECT ....'); // ! uses $db2 connection
    mysqli_query($db1'SELECT ....'); // Uses $db1 connection 
    That make sense?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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