Romanian PC Forum Sabitech Media - web design, gazduire web, promovare, seo, logo design si branding


Go Back   Romanian PC Forum > Software > Programare > Web

Web Totul despre web programming... dezbateri, nelamuriri, tutoriale...


Reply
 
Thread Tools
Old 21.10.2011, 20:10   #1
sdw
RPC Gold Member
 
Join Date: 02.03.2011
Age: 42
Posts: 978
Thanks: 20
Thanked 1,091 Times in 583 Posts
Default Un mic wrapper peste functiile mysql

Code:
<?php


class MySQL {
	private function __construct() {
		$user = "username";
		$pass = "parola";
		$db = "database";
		self::$connected = false;
		if(mysql_connect("localhost", $user, $pass))
			if(mysql_select_db($db))
				self::$connected = true;
	}

	public static function query($sql) {
		self::connect();
		self::$recordset = false;
		if(self::$connected) {
			self::$recordset = @mysql_query($sql);
			if(self::$recordset) return true;
		}
		return false;
	}

	public static function fetch() {
		if(self::$recordset) {
			return @mysql_fetch_array(self::$recordset);
		}
		return false;
	}

	public static function lastid() {
		if(self::$connected)
			return @mysql_insert_id();
		return false;
	}

	public static function lookup($sql) {
		self::query("$sql LIMIT 1");
		return self::fetch();
	}

	public static function escape($str) {
		self::connect();
		if(self::$connected)
			return mysql_real_escape_string($str);
		return "";
	}

	public static function connect() {
		if(!self::$instance)
			self::$instance = new self();
		return self::$instance;
	}

	private static $instance;
	private static $connected;
	private static $recordset;
}


?>
Exemplu de utilizare:

Code:
<table>
<?php

include "mysql.php";

$sql = "SELECT produs, pret FROM produse ORDER BY produs";
MySQL::query($sql);

while($row = MySQL::fetch()) {
  list($produs, $pret) = $row;
  ?>
  <tr>
    <td><?= $produs ?></td>
    <td><?= $pret ?></td>
  </tr>
  <?php
}

?>
</table>
PS @xvanish: ar fi util un plugin la forum care sa stie sa faca syntax-highlighting la codurile sursa (php, c++ etc).
__________________
Imi place Romanian PC Forum - www.rpc-forum.ro!
sdw is offline   Reply With Quote
The Following User Says Thank You to sdw For This Useful Post:
Alin99 (21.10.2011)
Old 22.10.2011, 15:58   #2
XVanish
RPC Administrator
 
XVanish's Avatar
 
Join Date: 03.06.2008
Location: Baia Mare
Age: 37
Posts: 5,965
Thanks: 3,662
Thanked 3,376 Times in 1,985 Posts
Send a message via Yahoo to XVanish Send a message via Skype™ to XVanish
Default Re: Un mic wrapper peste functiile mysql

Da, e o idee buna, o sa caut.
__________________
Internetul e distractie, nu pierde controlul!


Foloseste Google si YouTube inainte de a pune intrebari stupide!
XVanish is online now   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial - C ] Accesarea unei baze de date mysql High Devil Programare 5 26.06.2010 19:07
La peste kittmask Galerie foto 1 25.01.2010 21:38
Un peste este mancat de viu intr-un restaurant din China XVanish Offtopic 0 19.11.2009 10:05
problema Windows - se baga programele unul peste altul georgester Suport Tehnic 2 29.04.2009 15:08

 
Advertisement




camere foto digitale

aparate foto digitale


Partner Links
Sabitech Media - dezvoltare web, servicii media

RSP Forum - sateliti.info
Comunitate Satelitara






All times are GMT +2. The time now is 19:31.


Powered by vBulletin® - © Jelsoft Enterprises Ltd.
~ Copyright © 2007-2015 Romanian PC Forum ~
Toate drepturile rezervate

Romanian Sattelites Provider Wi-Fi Magazin