Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Databases Code Examples

Database and Recordset classes fo SyBASE Usage is obvious.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
Database and Recordset classes fo SyBASE Usage is obvious. <?php // Usage example // // require("sybase.php3"); // // $sybdb = new CSybDb("SYBASE", "http_user", "http_pass", "http_db"); // $sybrs = new CSybRs("select * from http_log", $sybdb); // // $sybrs->display(); // ... or do anything else // // $sybrs->destroy(); // $sybdb->destroy(); // class CSybDb { var $sybdb; function CSybDb($server, $user, $pass, $dbname = "") { $this->sybdb = sybase_connect($server, $user, $pass); if( $this->valid() && $dbname != "" ) { if( !sybase_select_db($dbname, $this->sybdb) ) { destroy(); } } } function destroy() { if( $this->valid() ) { sybase_close($this->sybdb); } $this->sybdb = 0; } function valid() { return $this->sybdb != 0; } }; class CSybRs { var $recs; var $rows; var $cols; var $crow; var $rarr; var $fail; function CSybRs($query, $sybdb) { $this->recs = 0; $this->rows = 0; $this->cols = 0; $this->fail = 1; $this->crow = 0; if( !$sybdb->valid() ) return; $this->recs = sybase_query($query, $sybdb->sybdb); if( !$this->recs ) return; $this->rows = sybase_num_rows($this->recs); $this->cols = sybase_num_fields($this->recs); $this->fail = 0; } function destroy() { if( !$this->recs ) return; // sybase_freeresult($this->recs); $this->recs = 0; } function valid() { return !$this->fail && $this->recs != 0; } function seek($nrow) { if( !$this->valid() ) return 0; if( $this->bof() && $this->eof() ) return 0; if( sybase_data_seek($this->recs, $nrow) ) { $this->crow = $nrow; $this->rarr = sybase_fetch_array($this->recs); if( $this->rarr ) { return 1; } } $this->fail = 1; return 0; } function eof() { return $this->crow == $this->rows; } function bof() { return $this->crow < 0; } function first() { $this->crow = 0; if( !$this->seek($this->crow) ) { // mark as bof $this->crow = -1; } } function prev() { if( $this->bof() ) return; $this->crow--; if( $this->bof() ) return; if( !$this->seek($this->crow) ) { // mark as bof $this->crow = -1; } } function next() { if( $this->eof() ) return; $this->crow++; if( $this->eof() ) return; $this->rarr = sybase_fetch_array($this->recs); if( !$this->rarr ) { // mark as eof $this->crow = $this->rows; } } function last() { $this->crow = $this->rows - 1; if( !$this->seek($this->crow) ) { // mark as eof $this->crow = $this->rows; } } function valueof($col) { if( !$this->valid() ) return; return $this->rarr[$col]; } function showheader($col, $fmt = "") { $fld = sybase_fetch_field($this->recs, $col); printf( "\t<th %s>%s</th>\n", $fmt, is_string($col) ? $col : $fld->name); } function showvalue($col, $fmt = "", $def = "?") { $v = $this->valueof($col); printf( "\t<td %s>%s</td>\n", $fmt, $v == "" ? $def : $v); } function display() { if( !$this->valid() ) return; printf( "<table cellspacing=1 cellpadding=1 border=1>\n"); printf( "<tr>\n"); for( $c = 0; $c < $this->cols; $c++ ) { $this->showheader($c); } printf( "</tr>\n"); $this->first(); while( !$this->eof() ) { printf( "<tr>\n"); for( $c = 0; $c < $this->cols; $c++ ) { $this->showvalue($c); } printf( "</tr>\n"); $this->next(); } printf( "</table>\n"); } }; ?>