SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Mysql_info

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mysql_info

    There's a really helpful function on php.net, but it's using ereg which is slower.

    PHP Code:
    function get_mysql_info($linkid null){
        
    $linkid$strInfo mysql_info($linkid) : $strInfo mysql_info();
       
        
    $return = array();
        
    ereg("Records: ([0-9]*)"$strInfo$records);
        
    ereg("Duplicates: ([0-9]*)"$strInfo$dupes);
        
    ereg("Warnings: ([0-9]*)"$strInfo$warnings);
        
    ereg("Deleted: ([0-9]*)"$strInfo$deleted);
        
    ereg("Skipped: ([0-9]*)"$strInfo$skipped);
        
    ereg("Rows matched: ([0-9]*)"$strInfo$rows_matched);
        
    ereg("Changed: ([0-9]*)"$strInfo$changed);
       
        
    $return['records'] = $records[1];
        
    $return['duplicates'] = $dupes[1];
        
    $return['warnings'] = $warnings[1];
        
    $return['deleted'] = $deleted[1];
        
    $return['skipped'] = $skipped[1];
        
    $return['rows_matched'] = $rows_matched[1];
        
    $return['changed'] = $changed[1];
       
        return 
    $return;

    Any chance someone could help me convert it ? i'm useless with text matching :S

    thanks for any help/support

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by WakeMeWithAKiss View Post
    Any chance someone could help me convert it ?
    Convert it to what?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh sorry >.>

    To using the preg functions instead.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone ? I've looked for tutorials to help me but couldn't find any decent ones :S any links to good tutorials atleast ?

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $t 'INSERT INTO ... SELECT ...
    String format: Records: 23 Duplicates: 0 Warnings: 0
    INSERT INTO ... VALUES (...),(...),(...)...
    String format: Records: 37 Duplicates: 0 Warnings: 0
    LOAD DATA INFILE ...
    String format: Records: 42 Deleted: 0 Skipped: 0 Warnings: 0
    ALTER TABLE
    String format: Records: 60 Duplicates: 0 Warnings: 0
    UPDATE
    String format: Rows matched: 65 Changed: 65 Warnings: 0'
    ;

    $ret = array();
    preg_match_all'/([a-z][a-z ]+): (\d+)/i'$t$m );
    for ( 
    $i 0; isset( $m[0][ $i ] ); $i++ ) {
        
    $name strtolowertrim$m[1][ $i ] ) );
        
        if ( !isset( 
    $ret$name ] ) )
            
    $ret$name ] = array();

        
    $ret$name ][] = $m[2][ $i ];
    }

    var_dump$ret ); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks ! : )
    I've edited it abit for my database class (just change $this->info() to mysql_info())

    This one will only process details about ONE query. Also they're saved as ints, not an an array of strings.

    PHP Code:
    public function getInfo()
    {
        
    $return = array();
        
    $matched null;
        
    preg_match_all('/([a-z][a-z ]+): (\d+)/i'$this->info(), $matched);
        for ( 
    $i 0; isset($matched[0][$i]); $i++ )
        {
            
    $name strtolower(trim($matched[1][$i]));
            if (
    $name == "Rows matched"$name "matched";
            
    $return[$name] = (int)$matched[2][$i];
        }
        
        return 
    $return;



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
  •